結果

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

ソースコード

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<ll> sieve(ll n) {
	vector<ll> ps;
	vector<bool> is_prime(n + 1, true);

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

	ll N, L;
	cin >> N >> L;

	vector<ll> ps = sieve(L);

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