結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー olpheolphe
提出日時 2016-11-15 00:45:21
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 589 ms / 1,000 ms
コード長 546 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 62,428 KB
実行使用メモリ 14,336 KB
最終ジャッジ日時 2024-12-16 01:45:50
合計ジャッジ時間 3,676 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "list"
#include "math.h"
using namespace std;

int N, L;
list <int>P;
long long int ans;
bool flag;

int main() {
	cin >> N >> L;
	P.push_back(2);
	for (int i = 3; i <= L/(N-1); i+=2) {
		flag = true;
		for (auto j = P.begin()++; j != P.end()&&(*j)<=sqrt(i); ++j) {
			if (i % (*j) == 0) {
				flag = false;
				break;
			}
		}
		if (flag) {
			P.push_back(i);
		}
	}
	for (auto i = P.begin(); i != P.end(); ++i) {
		if (L - (N - 1)*(*i) < 0)break;
		ans += L - (N - 1)*(*i) + 1;
	}
	cout << ans << "\n";
	return 0;
}
0