Project Euler [Problem 35]

時が経つのは超早い

3年たった。マジかよ。

問題

Circular primes

The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.

There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.

How many circular primes are there below one million?

私訳

循環素数

197 は, 各位を回転させた 197, 971, そして 719 がすべて素数となるため, 循環素数と呼ばれる

100 未満の循環素数は 13 個存在する : 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, そして 97.

100万未満のなかに循環素数はいくつ存在するか?

解答方針

100万までの素数表を作成し、そこから循環するものだけを取り出すのが簡単だろう。 幸い、循環するものは素数表に存在しているから、判定は容易である。 素数表を Set で実装するのがよさそうだ。