結果
問題 | No.889 素数! |
ユーザー |
![]() |
提出日時 | 2022-11-12 20:02:42 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,093 bytes |
コンパイル時間 | 1,877 ms |
コンパイル使用メモリ | 208,608 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-22 16:40:52 |
合計ジャッジ時間 | 3,479 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 61 |
ソースコード
import std;void main() {int N;readf("%d\n", N);int L = 64;auto sieve = new bool[](L);sieve[2..L] = true;uint d = 2;while (d * d < L) {if (sieve[d]) {foreach (i; iota(d*d, L, d)) {sieve[i] = false;}}++d;}auto primes = iota(L).filter!(i => sieve[i]).array;auto res = new string[](L);res[0] = "0", res[1] = "1";foreach (p; primes) {res[p] = "Sosu!";if (p ^^ 2 < L) res[p^^2] = "Heihosu!";if (p ^^ 3 < L) res[p^^3] = "Ripposu!";}foreach (i; 2 .. L) {if (i ^^ 2 < L) res[i^^2] = "Heihosu!";if (i ^^ 3 < L) res[i^^3] = "Ripposu!";}foreach (i; 2 .. L) {if (!res[i].empty) continue;int num = 1, div = 2;while (div * div <= i) {if (i % div == 0) {num += div;if (div * div != i) num += i / div;}++div;}res[i] = (num == i ? "Kanzensu!" : i.to!string);}res[N].writeln;}