結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー bal4ubal4u
提出日時 2019-04-16 07:49:49
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 31,408 KB
実行使用メモリ 6,772 KB
最終ジャッジ日時 2023-10-22 06:56:31
合計ジャッジ時間 1,506 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 16 ms
6,772 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 5 ms
6,772 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 5 ms
6,772 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 8 ms
6,772 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 5 ms
6,772 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 5 ms
6,772 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 7 ms
6,772 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 WA -
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 5 ms
6,772 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 7 ms
6,772 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.406 鴨等間隔の法則
// 2019.4.16 bal4u

#include <stdio.h>
#include <math.h>

#define MAX  5000000
char notPrime[MAX+2] = { 1,1,0,0,1 };			// zero: if prime 
void sieve(int max)
{
	int i, j, b;
	b = (int)sqrt((double)max);
	for (i = 3; i <= b; i += 2) {
		if (!notPrime[i]) {
			for (j = i * i; j < MAX; j += i) notPrime[j] = 1;
		}
	}
}

int main()
{
	int i, k, s, N, L, max;
	long long ans;

	scanf("%d%d", &N, &L);
	max = L / (N - 1);
	sieve(max);
	ans = 0;
	if (2 <= max) ans = L+1 - ((N-1) << 1);
	k = s = 0;  for (i = 3; i <= max; i += 2) {
		if (!notPrime[i]) k++, s += i;
	}
	if (k) ans += (long long)k * (L + 1) - (long long)(N - 1)*s;
	printf("%lld\n", ans);
	return 0;
}
0