結果
| 問題 | No.826 連絡網 | 
| コンテスト | |
| ユーザー |  ward1302 | 
| 提出日時 | 2019-05-03 21:42:34 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 132 ms / 2,000 ms | 
| コード長 | 574 bytes | 
| コンパイル時間 | 669 ms | 
| コンパイル使用メモリ | 76,400 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-24 02:15:50 | 
| 合計ジャッジ時間 | 2,619 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
int main() {
	int N, P; cin >> N >> P;
	int cnt=1;
	for(int i=N/2+1; i<=N; ++i){
	    bool flag=true;
	    bool is_p = i==P;
	    for(int h=2; h*h<=i; ++h){
	        if(i%h==0){
	            flag=false;
	            break;
	        }
	    }
	    if(flag) ++cnt;
	    if(is_p && flag){
	        cout << 1 << endl;
	        return 0;
	    }
	}
	cout << (P==1 ? 1 : N-cnt) << endl;
	return 0;
}
            
            
            
        