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