結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー masamasa
提出日時 2016-08-05 22:56:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 1,000 ms
コード長 1,010 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 78,448 KB
実行使用メモリ 43,420 KB
最終ジャッジ日時 2023-08-22 03:59:49
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 10 ms
7,056 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 80 ms
41,456 KB
testcase_06 AC 44 ms
24,132 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 10 ms
7,100 KB
testcase_20 AC 27 ms
15,148 KB
testcase_21 AC 12 ms
8,420 KB
testcase_22 AC 11 ms
7,412 KB
testcase_23 AC 18 ms
10,716 KB
testcase_24 AC 26 ms
15,088 KB
testcase_25 AC 42 ms
23,356 KB
testcase_26 AC 42 ms
23,376 KB
testcase_27 AC 8 ms
6,104 KB
testcase_28 AC 20 ms
11,764 KB
testcase_29 AC 41 ms
22,560 KB
testcase_30 AC 9 ms
6,696 KB
testcase_31 AC 34 ms
19,220 KB
testcase_32 AC 42 ms
22,908 KB
testcase_33 AC 85 ms
43,332 KB
testcase_34 AC 85 ms
43,420 KB
testcase_35 AC 77 ms
39,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

template <class T>
vector<bool> getIsPrime(T n) {
	vector<bool> p(n + 1, true);
	p[0] = p[1] = false;

	T limit = sqrt(n);
	for (T i = 4; i <= n; i += 2) {
		p[i] = false;
	}
	for (T i = 3; i <= limit; i += 2) {
		if (p[i]) {
			for (T j = i * i; j <= n; j += i) {
				p[j] = false;
			}
		}
	}

	return p;
}

template <class T>
vector<T> getPrimes(T n) {
	auto isPrime = getIsPrime(n);
	vector<T> primes((n + 1) / 2, 0);
	auto it = primes.begin();
	for (T i = 2; i <= n; i++) {
		if (isPrime[i]) {
			*it = i;
			it++;
		}
	}
	primes.erase(it, primes.end());
	return primes;
}

int main() {
	long long n, l;

	cin >> n >> l;
	vector<long long> primes = getPrimes(l);


	long long ans = 0;
	for (auto p : primes) {
		long long total_len = p * (n - 1);
		if (total_len > l) {
			break;
		}
		ans += l - total_len + 1;
	}

	cout << ans << endl;
	return 0;
}
0