結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
![]() |
提出日時 | 2019-04-16 07:49:49 |
言語 | C (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 705 bytes |
コンパイル時間 | 179 ms |
コンパイル使用メモリ | 31,488 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 08:10:06 |
合計ジャッジ時間 | 1,394 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 24 WA * 7 |
ソースコード
// yukicoder: No.406 鴨等間隔の法則 // 2019.4.16 bal4u #include <stdio.h> #include <math.h> #define MAX 5000000 char notPrime[MAX+2] = { 1,1,0,0,1 }; // zero: if prime void sieve(int max) { int i, j, b; b = (int)sqrt((double)max); for (i = 3; i <= b; i += 2) { if (!notPrime[i]) { for (j = i * i; j < MAX; j += i) notPrime[j] = 1; } } } int main() { int i, k, s, N, L, max; long long ans; scanf("%d%d", &N, &L); max = L / (N - 1); sieve(max); ans = 0; if (2 <= max) ans = L+1 - ((N-1) << 1); k = s = 0; for (i = 3; i <= max; i += 2) { if (!notPrime[i]) k++, s += i; } if (k) ans += (long long)k * (L + 1) - (long long)(N - 1)*s; printf("%lld\n", ans); return 0; }