結果

問題 No.826 連絡網
ユーザー 東前頭十一枚目東前頭十一枚目
提出日時 2019-05-30 00:22:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 992 bytes
コンパイル時間 1,364 ms
コンパイル使用メモリ 166,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 05:22:56
合計ジャッジ時間 2,634 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 34 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
testcase_14 AC 24 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 15 ms
5,376 KB
testcase_17 AC 11 ms
5,376 KB
testcase_18 AC 9 ms
5,376 KB
testcase_19 AC 43 ms
5,376 KB
testcase_20 AC 41 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 11 ms
5,376 KB
testcase_23 AC 16 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 52 ms
5,376 KB
testcase_26 AC 7 ms
5,376 KB
testcase_27 AC 36 ms
5,376 KB
testcase_28 AC 25 ms
5,376 KB
testcase_29 AC 11 ms
5,376 KB
testcase_30 AC 51 ms
5,376 KB
testcase_31 AC 14 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

bool is_prime(int n){
    if(n<2) return 0; //素数は2以上
	if(n==2 || n==3) return 1; //2,3は素数
    if(n%2==0 || n%3==0) return 0; //2,3の倍数を消去
    //以降素数は6k±1にしかない
    if(n%6!=1 && n%6!=5) return 0;
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0) return 0; //6k-1
        if(n%(i+2)==0) return 0; //6k+1
    }
    return 1;
}

int main(){
    int n,p; cin>>n>>p;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    int ans=n-1;
    for(int i=2;i<=n;i++){
        if(n/i==1 and is_prime(i)){
            if(i==p){
                cout<<1<<endl;
                return 0;
            }
            ans--;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0