2008-04-13から1日間の記事一覧

Problem 10

素数関係なので着手. The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million. 訳 10未満の素数の和は2 + 3 + 5 + 7 = 17.2,000,000未満のすべての素数の和を求めよ. [Haskell] 前に考えたものをそのま…

Problem 9

A Pythagorean triplet is a set of three natural numbers, [tex:$a 訳 ピタゴラス数とは自然数の三つ組で[tex:$a [Haskell] {- Project Euler Problem 9 e9.hs -} line:: Int -> [(Int,Int)] line k = [(i,k-i) | i<-[0..k], i*k == 500, i>k-i ] lattice:…

素数を列挙する4

「mod 6で1か5」を探索する方法でいってみます. use Benchmark; $x=primefactory2(); $count=5000; timethese($count, {'p1' => '$x->();', } ); sub next_cand{ $_[0] + 2 * ($_[0] % 6 ==5) + 4*($_[0] % 6 ==1); } sub primefactory2{ my @primes=(2,3,5…

素数を列挙する3

キーボードが小さくなって誤入力倍増キャンペーン開催中. ##単純なエラトステネスの篩 use Benchmark; $x=primefactory1(); $count=5000; $i=0; timethese($count, {'p1' => '$x->();', } ); sub primefactory1{ my @primes=(2,3); my $state=-1; return su…