結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー femto
提出日時 2016-08-05 22:40:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 844 bytes
コンパイル時間 750 ms
コンパイル使用メモリ 81,940 KB
実行使用メモリ 8,748 KB
最終ジャッジ日時 2024-11-07 00:27:31
合計ジャッジ時間 2,803 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;
template<typename T> void setmin(T& a, T& b) { a = min(a, b); }
template<typename T> void setmax(T& a, T& b) { a = max(a, b); }

typedef long long ll;

vector<int> sieve(int n) {
	vector<int> ps;
	vector<bool> is_prime(n + 1, true);

	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= n; i++) {
		if(is_prime[i]) {
			ps.push_back(i);
			for(int j = 2 * i; j <= n; j += i) {
				is_prime[j] = false;
			}
		}
	}
	return ps;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, L;
	cin >> N >> L;

	vector<int> ps = sieve(L);

	ll ans = 0;
	for(int p : ps) {
		int rem = L - (N + (N - 1) * (p - 1) - 1);
		if(rem >= 0) {
			ans += rem + 1;
		}
	}
	cout << ans << endl;
}
0