結果

問題 No.826 連絡網
ユーザー 6soukiti29
提出日時 2019-05-03 23:01:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 431 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 165,688 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-24 02:32:46
合計ジャッジ時間 2,931 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int N, P;
bool sosuu[1000010];

int main() {
	
	cin >> N >> P;
	int ans = N - 1;
	for (int i = 0; i <= N; i++) sosuu[i] = false;
	
	for (int i = 2; i <= N; i++) {
		if (sosuu[i] == false) {
			int n = i * 2;
			while (n <= N) {
				sosuu[n] = true;
				n += i;
			}
			if (i * 2 > N) ans -= 1;
		}
	}
	
	if ((sosuu[P] == false) and P * 2 > N) cout << 1;
	else cout << ans << endl;
}

0