結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー antaanta
提出日時 2016-08-05 22:35:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 1,000 ms
コード長 1,845 bytes
コンパイル時間 1,688 ms
コンパイル使用メモリ 169,136 KB
実行使用メモリ 24,300 KB
最終ジャッジ日時 2023-08-22 02:28:56
合計ジャッジ時間 3,350 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 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 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 4 ms
5,252 KB
testcase_20 AC 9 ms
9,644 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 15 ms
13,760 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 7 ms
8,388 KB
testcase_33 AC 36 ms
24,280 KB
testcase_34 AC 36 ms
24,300 KB
testcase_35 AC 13 ms
12,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

vector<int> primes;
vector<int> smallestPrimeFactor;
void linearSieve(int n) {
	if(n < 1) n = 1;
	if((int)smallestPrimeFactor.size() >= n + 1) return;
	int primePiBound = n < 20 ? n - 1 : (int)(n / (log(n * 1.) - 2) + 2);
	primes.assign(primePiBound + 1, numeric_limits<int>::max());
	int P = 0;
	smallestPrimeFactor.assign(n + 1, 0);
	smallestPrimeFactor[1] = 1;
	int n2 = n / 2, n3 = n / 3, n5 = n / 5;
	if(n >= 2)
		primes[P ++] = 2;
	if(n >= 3)
		primes[P ++] = 3;
	for(int q = 2; q <= n; q += 2)
		smallestPrimeFactor[q] = 2;
	for(int q = 3; q <= n; q += 6)
		smallestPrimeFactor[q] = 3;
	for(int q = 5; q <= n5; q += 2) {
		if(smallestPrimeFactor[q] == 0)
			primes[P ++] = smallestPrimeFactor[q] = q;
		int bound = smallestPrimeFactor[q];
		for(int i = 2; ; ++ i) {
			int p = primes[i];
			if(p > bound) break;
			int pq = p * q;
			if(pq > n) break;
			smallestPrimeFactor[pq] = p;
		}
	}
	for(int q = (n5 + 1) | 1; q <= n; q += 2) {
		if(smallestPrimeFactor[q] == 0)
			primes[P ++] = smallestPrimeFactor[q] = q;
	}
	primes.resize(P);
}

int main() {
	int N; int L;
	while(~scanf("%d%d", &N, &L)) {
		linearSieve(L / (N - 1) + 1);
		ll ans = 0;
		for(int d : primes) {
			ans += max(0, L + 1 - d * (N - 1));
		}
		printf("%lld\n", ans);
	}
	return 0;
}
0