結果

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

ソースコード

diff #

#include<iostream>
#include<vector>

using namespace std;



vector<int> sieve(int n) {
	vector<int> res(n);
	for (int i = 0; i < n; i++)
	{
		res[i] = 1;
	}
	if (n >= 2)
		res[0] = res[1] = 0;
	else {
		for (int i = 0; i < n; i++)
		{
			res[i] = 0;
		}
	}
	for (int i = 2; i*i < n; i++)
	{
		if (res[i] == 1) {
			for (int j = 2 * i; j < n; j += i)
			{
				res[j] = 0;

			}
		}
	}
	return res;
}

int main()
{
	int N, L;
	cin >> N >> L;
	long long ans = 0;
	vector<int> v = sieve(L);
	
	for (int i = 1; i*(N-1) <= L; i++)
	{
		if(v[i] ==1)
			ans += L - i*(N - 1) + 1;
		
	}
	cout << ans << endl;

	return 0;
}
0