Project Euler [Problem 49]
みんな大好き素数列シリーズ
差が維持されて~かつ順列になってるやつ。
問題
Prime permutations
The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.
There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.
What 12-digit number do you form by concatenating the three terms in this sequence?
私訳
素数の並べ替え
等差数列 1487, 4817, 8147 は、公差が 3330 で、 ふたつの点で特異である。
- すべての項が素数
- 4桁の整数それぞれがお互いに並べ替えになっている
このような性質の 1, 2, 3 桁の素数の三つ組は存在しないが、 4 桁ではもう一組だけ存在する。
もう一組を連結した 12 桁の整数はいくつか?
解答方針
4桁の素数を全部出してから考えますか 4桁の素数で順列になってる p[i], p[j] 見つけて、 差がきっと 9 の倍数になるはずで、かつ p[j] + (p[j] - p[i]) も素数になってるはず、 とやったらあっさり。