結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー bal4ubal4u
提出日時 2019-04-16 07:43:09
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 37 ms / 1,000 ms
コード長 634 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 31,740 KB
実行使用メモリ 6,796 KB
最終ジャッジ日時 2023-10-22 06:56:20
合計ジャッジ時間 2,783 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 18 ms
6,796 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 5 ms
6,796 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 6 ms
6,796 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,796 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 5 ms
6,796 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 5 ms
6,796 KB
testcase_19 AC 19 ms
6,796 KB
testcase_20 AC 21 ms
6,796 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 9 ms
6,796 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 23 ms
6,796 KB
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,796 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 7 ms
6,796 KB
testcase_32 AC 20 ms
6,796 KB
testcase_33 AC 37 ms
6,796 KB
testcase_34 AC 25 ms
6,796 KB
testcase_35 AC 22 ms
6,796 KB
権限があれば一括ダウンロードができます

ソースコード

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, N, L, max;
	long long ans;

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