Project Euler 3週目

Project Euler 3週目。後半サボったのであまり進んでいない。とはいえ一応記録は残しておく。

http://projecteuler.net
http://odz.sakura.ne.jp/projecteuler/ 問題の和訳

8:
Discover the largest product of five consecutive 
digits in the 1000-digit number.

1000桁数は文字列として持っておいて計算時に数値化した。

9:
Find the only Pythagorean triplet, {a, b, c}, for 
which a + b + c = 1000.

aを奇数、bを偶数として大きい方から見つかるまで探した。

10:
Calculate the sum of all the primes below two million.

エラトステネスで素数判定して足す。

11:
What is the greatest product of four numbers on the 
same straight line in the 20 by 20 grid?

各座標について右、下、右上、右下を計算。問題のgridを配列に突っ込むのがちょい面倒。

12:
What is the value of the first triangle number to have 
over five hundred divisors?

素因数分解すればdivisors(約数)の数はすぐわかる。

13:
Find the first ten digits of the sum of one-hundred 
50-digit numbers.

低い桁から足して10で割って四捨五入を繰り返した。


数論のすばらしく面白い教科書。オススメ!

プログラミングコンテストの実力を磨くならこれ