! Copyright (c) 2007 Samuel Tardieu. ! See http://factorcode.org/license.txt for BSD license. USING: arrays kernel lists lists.lazy math.algebra math math.functions math.order math.primes math.ranges project-euler.common sequences ; IN: project-euler.134 ! http://projecteuler.net/index.php?section=problems&id=134 ! DESCRIPTION ! ----------- ! Consider the consecutive primes p1 = 19 and p2 = 23. It can be verified that ! 1219 is the smallest number such that the last digits are formed by p1 whilst ! also being divisible by p2. ! In fact, with the exception of p1 = 3 and p2 = 5, for every pair of ! consecutive primes, p2 p1, there exist values of n for which the last digits ! are formed by p1 and n is divisible by p2. Let S be the smallest of these ! values of n. ! Find S for every pair of consecutive primes with 5 p1 1000000. ! SOLUTION ! -------- ! Compute the smallest power of 10 greater than or equal to m : next-power-of-10 ( m -- n ) 10 swap log10 ceiling >integer ^ ; foldable : euler134 ( -- answer ) 0 5 lprimes-from uncons swap [ 1000000 > ] luntil [ [ s + ] keep ] leach drop ; ! [ euler134 ] 10 ave-time ! 2430 ms run / 36 ms GC ave time - 10 trials MAIN: euler134