結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
![]() |
提出日時 | 2016-12-03 00:06:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 135 ms / 1,000 ms |
コード長 | 1,023 bytes |
コンパイル時間 | 894 ms |
コンパイル使用メモリ | 90,008 KB |
実行使用メモリ | 17,152 KB |
最終ジャッジ日時 | 2024-12-16 01:47:17 |
合計ジャッジ時間 | 3,135 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 31 |
ソースコード
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <typeinfo> #include <fstream> #include <climits> #include <functional> #define REP(i,n) for(int i = 0;i < n;i++) using namespace std; typedef long long ll; const int INF = INT_MAX / 4; const int max_n = 1e3; vector<int> eratosthenes(int n) { bool arr[n]; REP(i, n) arr[i] = 1; for(int i = 2;i < n;i++){ if (arr[i]) { int c = i * 2; while (c < n) { arr[c] = 0; c += i; } } } vector<int> v; for(int i = 2;i < n;i++){ if (arr[i]) { v.push_back(i); } } return v; } int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N, L; cin >> N >> L; vector<int> v = eratosthenes(L); ll cnt = 0; int d = 0; for(auto iter = v.begin();iter != v.end();iter++){ d = L - *iter * (N-1) + 1; if (d > 0) cnt += d; else break; } cout << cnt << "\n"; return 0; }