結果

問題 No.826 連絡網
ユーザー kamiyomokikanukamiyomokikanu
提出日時 2019-05-04 01:06:31
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,288 bytes
コンパイル時間 351 ms
コンパイル使用メモリ 52,140 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 08:53:11
合計ジャッジ時間 3,777 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 2 ms
4,380 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 1 ms
4,384 KB
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include<iostream>

#define NMAX (100000)

//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;

	//WA対策。Pが1なら1を出力
	if(P==1){
		std::cout<<"1"<<std::endl;
		return 0;
	}

	//篩で素数を算出。
	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