結果

問題 No.826 連絡網
ユーザー kamiyomokikanukamiyomokikanu
提出日時 2019-05-04 01:02:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,197 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 52,180 KB
実行使用メモリ 7,372 KB
最終ジャッジ日時 2023-08-30 08:53:00
合計ジャッジ時間 2,077 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 10 ms
7,044 KB
testcase_13 AC 5 ms
4,756 KB
testcase_14 AC 8 ms
5,772 KB
testcase_15 AC 2 ms
4,508 KB
testcase_16 AC 5 ms
5,928 KB
testcase_17 AC 4 ms
4,768 KB
testcase_18 AC 4 ms
4,384 KB
testcase_19 AC 11 ms
6,624 KB
testcase_20 AC 11 ms
6,572 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 5 ms
4,760 KB
testcase_23 AC 5 ms
5,936 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 13 ms
7,372 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 10 ms
6,288 KB
testcase_28 AC 8 ms
6,488 KB
testcase_29 AC 4 ms
4,752 KB
testcase_30 AC 13 ms
7,208 KB
testcase_31 AC 5 ms
5,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//Y街には家1~家Nがあり、一人ずつ住んでいる。
//青木君は家Pに住む
//※互いに素---最大公約数が1
//家1~家N同士は繋がっているが、互いに素な家同士は繋がっていない。
//家の数Nと、青木君Pが与えられるので、青木君と繋がってる数を考える
//素数以外はなんやかんやつながる。素数は*2がN以内にあればつながる。で考える。

#include<iostream>

#define NMAX (1000000)

//PRIME_NUM 素数
//DEVIS_NUM not素数
#define PRIME_NUM 0
#define DEVIS_NUM 1

int main(void){

	int N,P;
	int pri[NMAX+1];

	std::cin>>N>>P;

	//篩で素数を算出。
	for(int i=0;i<=N;i++){
		pri[i]=PRIME_NUM;
	}

	for(int i=2;i<=N;i++){
		if(pri[i]==PRIME_NUM){
			for(int j=i*2;j<=N;j+=i){
				pri[j]=DEVIS_NUM;
			}
		}
	}

	//Pが素数でP*2<Nなら、どことも繋げない。
	if(pri[P]==PRIME_NUM && P*2<N){
		std::cout<<"1"<<std::endl;
		return 0;
	}
	
	//素数に関して考慮しながら数える
	int ans=0;
	for(int i=2;i<=N;i++){
		//素数かつ、*2がN以上ならカウントしない
		if(!(pri[i]==PRIME_NUM && i*2>N)){
			ans++;
		}
	}

	std::cout<<ans<<std::endl;

	return 0;
}
0