Project Euler 390

http://projecteuler.net/index.php?section=problems&id=390

40着。2時間以上かけて下準備してそれを使って0.36秒。