結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー togari_takamoto
提出日時 2016-08-05 22:40:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 100 ms / 1,000 ms
コード長 833 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 165,240 KB
実行使用メモリ 9,804 KB
最終ジャッジ日時 2024-12-15 20:18:21
合計ジャッジ時間 3,177 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)

vb eratosthenes(ll n) {
	vb t(n + 1, true); t[0] = t[1] = false;
	for (ll i = 2; i <= n; ++i) if (t[i]) {
		for (ll j = 2 * i; j <= n; j += i) t[j] = false;
	}
	return t;
}

vl compress(const vb & t) {
	vl v; v.reserve((ll)(1.2 * t.size() / log(t.size())));
	REP(i, t.size()) if (t[i]) v.push_back(i);
	return v;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, l; cin >> n >> l;
	auto ps = compress(eratosthenes(l));
	ll sum = 0;
	for (ll p : ps) {
		ll rest = l - p * (n - 1);
		if (rest < 0) break;
		sum += rest + 1;
	}
	cout << sum << endl;
	return 0;
}
0