結果

問題 No.407 鴨等素数間隔列の数え上げ
コンテスト
ユーザー suppy193
提出日時 2017-01-31 15:47:27
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 728 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 216 ms
コンパイル使用メモリ 40,184 KB
最終ジャッジ日時 2026-02-24 00:14:05
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 22 WA * 5 TLE * 2 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int isprime(long long int n)
{
	int i;
	if(n == 2){
		return 1;
	}
	if(n % 2 == 0){
		return 0;
	}
	for(i = 3;i <= sqrt(n);i += 2){
		if(n % i == 0){
			return 0;
		}
	}
	return 1;
	
}

int main(void) {
	long long int n, l;
	long long int d_max;
	long long int i, j;
	int flag;
	long long int count = 0;
	scanf("%lld%lld", &n, &l);
	d_max = l / (n - 1);

	if(d_max >= 2){
		count += l - 2 * (n - 1) + 1;
	}
	if(d_max >= 3){
		count += l - 3 * (n - 1) + 1;
	}
	for(i = 1;i <= d_max / 6;i++){
		if(isprime(6 * i - 1) == 1){
			count += l - (6 * i - 1) * (n - 1) + 1;
		}
		if(isprime(6 * i + 1) == 1){
			count += l - (6 * i + 1) * (n - 1) + 1;
		}
	}
	printf("%lld\n", count);
	
	return 0;
}
0