結果

問題 No.826 連絡網
ユーザー uchiiiiuchiiii
提出日時 2020-07-30 02:35:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,806 bytes
コンパイル時間 3,241 ms
コンパイル使用メモリ 225,976 KB
実行使用メモリ 5,440 KB
最終ジャッジ日時 2023-09-13 19:42:31
合計ジャッジ時間 5,533 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------

map<int,int> factorize(int n) {
    map<int, int> ans;
    for(int i=2;i*i<=n;i++) {
        while(n%i==0) {
            ans[i]++;
            n /= i;
        }
    }
    if(n!=1) ans[n]++;
    return ans;
}

vector<int> prime(int n) {
    vector<int> ans;
    vector<bool> visited(n+1, false);
    ans.push_back(2);
    for(int i=3;i<=n;i+=2) {
        if(visited[i]) continue;
        ans.push_back(i);
        for(int j=i+i; j<=n; j+=i) visited[i] = true;
    }
    return ans;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n,p; cin >> n >> p;
    
    auto mp = factorize(p);
    int cnt = 0;
    int times = 0;

    if(p==1) {
        cout << 1 << endl;
        return 0;
    }

    for(auto &[k,v]:mp) {
        cnt++;
        times = v;
    }

    if(cnt == 1 and times==1) {
        cout << 1 << endl;
        return 0;
    }

    auto primes = prime(n);
    int ans = 1;
    for(auto &e: primes) 
    {
        if(e > n/2) ans ++;
    }
    cout << n-ans << endl;
    return 0;
}
0