1 ! Copyright (c) 2009 Guillaume Nargeot.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: math.primes.factors project-euler.common ranges sequences
7 ! https://projecteuler.net/problem=72
12 ! Consider the fraction, n/d, where n and d are positive
13 ! integers. If n<d and HCF(n,d)=1, it is called a reduced proper
16 ! If we list the set of reduced proper fractions for d ≤ 8 in
17 ! ascending order of size, we get:
19 ! 1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7,
20 ! 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
22 ! It can be seen that there are 21 elements in this set.
24 ! How many elements would be contained in the set of reduced
25 ! proper fractions for d ≤ 1,000,000?
31 ! The answer can be found by adding totient(n) for 2 ≤ n ≤ 1e6
33 : euler072 ( -- answer )
34 2 1000000 [a..b] [ totient ] map-sum ;
36 ! [ euler072 ] 100 ave-time
37 ! 5274 ms ave run time - 102.7 SD (100 trials)