Project Euler 5週目
Project Euler 5週目。25問目クリアでようやくレベル1。遅れてます。
http://projecteuler.net
http://odz.sakura.ne.jp/projecteuler/ 問題の和訳
23: Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.
事前に範囲内のabundant numbersを計算しておいて、2重ループでabundant numbersの和になっている数をハッシュに。最後にハッシュにヒットしない数を足す。あまり早くない。もっといい方法があるのかなあ。
24: What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
まともにパターン列挙してやると非常に遅いので、最初に0!〜9!を計算しておいて、深さ0なら9!ずつ位置を進めて、という感じで範囲を絞り込みつつ再帰呼び出し。これは綺麗に解けた気がする。解いていて面白かった。
25: What is the first term in the Fibonacci sequence to contain 1000 digits?
恒例の多倍長整数型先生の出番ですね(キリッ
数論のすばらしく面白い教科書。オススメ!
プログラミングコンテストの実力を磨くならこれ