結果
問題 | No.407 鴨等素数間隔列の数え上げ |
ユーザー |
![]() |
提出日時 | 2023-12-11 04:03:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 817 bytes |
コンパイル時間 | 1,057 ms |
コンパイル使用メモリ | 105,572 KB |
最終ジャッジ日時 | 2025-02-18 10:18:06 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 3 RE * 1 |
other | AC * 4 WA * 16 RE * 11 |
ソースコード
#include<iostream> #include<string> #include<algorithm> #include<cctype> #include<set> #include<bitset> #include<math.h> #include<map> #include<queue> #include<iomanip> using namespace std; using ll = long long; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int n, l, max1 = 0; ll ans = 0; cin >> n >> l; int MAX = max(1, l/(n-1)); vector<int> p(MAX+1, 1), primes; p[0] = 0; p[1] = 0; for (int i = 2; i <= MAX; i++){ if (p[i]) primes.push_back(i); for (int j = i*2; j <= MAX; j += i){ p[j] = 0; } } if (!primes.size()) primes.push_back(MAX); for (int i = 0; primes[i]*(n-1) <= l; i++){ max1 = primes[i]*(n-1); if ((l - max1 + 1)>0) ans += (l - max1 + 1); } cout << ans << endl; }