結果

問題 No.826 連絡網
ユーザー rpy3cpprpy3cpp
提出日時 2019-05-03 22:58:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 773 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 165,528 KB
実行使用メモリ 7,144 KB
最終ジャッジ日時 2023-08-30 06:34:41
合計ジャッジ時間 5,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 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 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 1 ms
4,376 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 #

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, P;
    cin >> N >> P;
    if (P == 1){
        cout << 1 << endl;
        return 0;
    }
    vector<int> prime(N + 1, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int p = 2; p <= N; ++p){
        if (prime[p] == 0) continue;
        for (int pp = p * p; pp <= N; pp += p) prime[pp] = 0;
    }
    int min_p = P;
    for (int p = 2; p <= P; ++p){
        if (P % p == 0 and prime[p] == 1){
            min_p = p;
            break;
        }
    }
    if (min_p * 2 <= N){
        int rev = 1;
        for (int i = N/2 + 1; i <= N; ++i) rev += prime[i];
        cout << (N - rev) << endl;
    }else{
        cout << 1 << endl;
    }
    return 0;
}

0