diff --git a/project_euler/problem_72/__init__.py b/project_euler/problem_72/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/project_euler/problem_72/sol1.py b/project_euler/problem_72/sol1.py new file mode 100644 index 000000000000..846396ab0f9c --- /dev/null +++ b/project_euler/problem_72/sol1.py @@ -0,0 +1,46 @@ +""" +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 + """ + + phi = [i - 1 for i in range(limit + 1)] + + for i in range(2, limit + 1): + for j in range(2 * i, limit + 1, i): + phi[j] -= phi[i] + + return sum(phi[2 : limit + 1]) + + +if __name__ == "__main__": + print(solution())