結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
![]() |
提出日時 | 2023-12-11 03:50:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 826 bytes |
コンパイル時間 | 1,106 ms |
コンパイル使用メモリ | 106,268 KB |
最終ジャッジ日時 | 2025-02-18 10:17:57 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 28 RE * 3 |
ソースコード
#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, max = 0; ll ans = 0; cin >> n >> l; int MAX = (l+1)/(n-1) + 1; vector<int> p(MAX, 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) && primes[i]; i++){ max = primes[i]*(n-1); if ((l - max + 1)>0) ans += (l - max + 1); } cout << ans << endl; }