結果

問題 No.2016 Countdown Divisors
ユーザー umimel
提出日時 2022-07-22 21:48:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,060 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 182,288 KB
実行使用メモリ 15,648 KB
最終ジャッジ日時 2024-07-04 06:00:21
合計ジャッジ時間 5,461 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 1
other AC * 1 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll N_MAX = 2e5;

map<ll, ll> mp;
void dfs(ll x){
    if(mp.find(x) != mp.end()) return;
    ll cnt = 1;
    ll y = x;
    for(ll i=2; i*i<=x; i++){
        if(y%i != 0) continue;
        ll c = 0;
        while(y%i == 0){
            y/=i;
            c++;
        }

        cnt *= (c+1);
    }

    if(y != 1) cnt*=2;

    dfs(x - cnt);
    mp[x] = mp[x-cnt];
    return;
}

int main(){
    ll t;
    cin >> t;

    vector<pll> a(t);
    rep(i, t){
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(all(a));

    mp[1] = 1;
    mp[2] = 2;
    vector<ll> ans(t);
    rep(i, t){
        dfs(a[i].fi);
        ans[a[i].se] = mp[a[i].fi];
    }

    rep(i, t) cout << ans[i] << endl;
}
0