""" Problem 72 Counting fractions: https://projecteuler.net/problem=72 Description: Consider the fraction, n/d, where n and d are positive integers. If n int: """ Returns an integer, the solution to the problem >>> solution(10) 31 >>> solution(100) 3043 >>> solution(1_000) 304191 """ # generating an array from -1 to limit phi = np.arange(-1, limit) for i in range(2, limit + 1): if phi[i] == i - 1: ind = np.arange(2 * i, limit + 1, i) # indexes for selection phi[ind] -= phi[ind] // i return int(np.sum(phi[2 : limit + 1])) if __name__ == "__main__": print(solution())