結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー ikd
提出日時 2016-08-05 23:43:17
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 250 ms / 1,000 ms
コード長 699 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 59,452 KB
実行使用メモリ 81,780 KB
最終ジャッジ日時 2024-12-15 22:22:03
合計ジャッジ時間 3,270 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<math.h>

using namespace std;
long long arr[10000000];

void Eratosthenes(long long N){
	for(long long i=0; i<N; i++){
		arr[i]=1;
	}
	for(long long i=2; i<sqrt(N); i++){
		if(arr[i]){
			for(long long j=0; i*(j + 2)<N; j++){
				arr[i*(j+2)]=0;
			}
		}
	}
/*
	for(long long i = 2; i < N; i++){
		if(arr[i]){
			//cout << i << endl;
		}
	}
*/
    arr[1]=0;
    arr[0]=-1;
}

int main(){

    long long N, L;
    cin>> N>> L;

    Eratosthenes(L);

    long long ans=0;
    for(long long i=2; i<=L; i++){
        if(arr[i]==0) continue;
        long long mi=(N-1)*i;
        if(mi>L) continue;
        ans=ans+(L-mi+1);
    }

    printf("%lld\n", ans);

    return 0;
}
0