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