2010-03-11から1日間の記事一覧

Project Euler 78

http://projecteuler.net/index.php?section=problems&id=78 まともに計算すると遅いので、メモ化する。 コンパイルするときは --makeをつける。それでもPython並みに遅い。 import Data.Map (Map, (!), empty, insert, lookup) n = 10^6 f m 0 = (insert 0 …

Project Euler 3

http://projecteuler.net/index.php?section=problems&id=3 素因数分解をする。 C++ではタプルが使えるのでこれを使う、pairでもいいが。 #include <iostream> #include <tuple> using namespace std; typedef tuple<int,int> Fact; int main() { Fact f = Fact(2, 3); cout << get<0>(</int,int></tuple></iostream>…