結果

問題 No.2751 429-like Number
ユーザー GOTKAKOGOTKAKO
提出日時 2024-05-10 21:34:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,770 bytes
コンパイル時間 2,748 ms
コンパイル使用メモリ 208,536 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-05-10 21:35:02
合計ジャッジ時間 9,220 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 10 ms
6,940 KB
testcase_02 AC 15 ms
6,940 KB
testcase_03 AC 15 ms
6,940 KB
testcase_04 AC 12 ms
6,944 KB
testcase_05 AC 11 ms
6,940 KB
testcase_06 AC 15 ms
6,940 KB
testcase_07 AC 1,077 ms
6,940 KB
testcase_08 AC 17 ms
6,940 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Modint64{
    //2^62未満&奇数modのみ.
    using Mint = Modint64;
    using u64 = uint64_t;
    using u128 = __uint128_t;
    static u64 mod,mod2,invmod,t128;
    u64 v = 0;
 
    Modint64(){v = 0;} Modint64(long long w){v = reduce((u128(w)+mod)*t128);}
    u64 val()const{
        u64 ret = reduce(v);
        return ret >= mod ? ret-mod : ret;
    }
    static u64 getmod(){return mod;}
    static u64 getinvmod(){
        u64 ret = mod;
        for(int i=0; i<5; i++) ret *= 2-mod*ret;
        return ret;
    }
    static void setmod(u64 m){
        assert((m<(1LL<<62)) && (m&1));
        mod = m; mod2 = m*2;
        t128 = -u128(mod)%mod;
        invmod = getinvmod();
    }
    static u64 reduce(const u128 &v){return (v+u128(u64(v)*u64(-invmod))*mod) >> 64;}
 
    Mint operator+(const Mint &b)const{return Mint(*this)+=b;}
    Mint operator-(const Mint &b)const{return Mint(*this)-=b;}
    Mint operator*(const Mint &b)const{return Mint(*this)*=b;}
    Mint operator/(const Mint &b)const{return Mint(*this)/=b;}
    Mint operator-()const{return Mint()-Mint(*this);}
    Mint& operator+=(const Mint &b){
        v += b.v;
        if(v >= mod2) v -= mod2;
        return *this; 
    }
    Mint& operator-=(const Mint &b){
        v += mod2-b.v;
        if(v >= mod2) v -= mod2;
        return *this;
    }
    Mint& operator*=(const Mint &b){
        v = reduce(u128(v)*b.v);
        return *this;
    }
    Mint& operator/=(const Mint &b){
        *this *= b.inv();
        return *this;
    }
    Mint pow(u128 b)const{
        Mint ret(1),p(*this);
        while(b){
            if(b&1) ret *= p;
            p = p*p; b >>= 1;
        }
        return ret;
    }
    Mint inv()const{return pow(mod-2);}
    
    bool operator==(const Mint &b)const{return (v >= mod?v-mod:v) == (b.v >= mod?b.v-mod:b.v);}
    bool operator!=(const Mint &b)const{return (v >= mod?v-mod:v) != (b.v >= mod?b.v-mod:b.v);}
};
typename Modint64::u64
Modint64::mod,Modint64::mod2,Modint64::invmod,Modint64::t128;
 
bool MillerRabin(long long N,vector<long long> A){
    using Mint = Modint64;
    Mint::setmod(N);
    int s = 0; long long d = N-1;
    while(d%2 == 0){s++,d >>= 1;}
    for(auto a : A){
        if(N <= a) return true;
        int t = 0; Mint x = Mint(a).pow(d);
        if(x != 1){
            for(; t < s; t++){
                if(x == N-1) break;
                x *= x;
            }
            if(t == s) return false;
        }
    }
    return true;
}
bool isprime(long long N){
    if(N <= 1) return false;
    if(N == 2) return true;
    if(N%2 == 0) return false;
    if(N < 475912314) return MillerRabin(N,{2,7,61});
    return MillerRabin(N,{2,325,9375,28178,450775,9780504,1795265022});
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Q; cin >> Q;
    int Need = 1000000;
    vector<int> allp;
    vector<bool> prime(Need+1,true);
    prime.at(0) = false; prime.at(1) = false;
    for(int i=2; i<=Need; i++){
        if(!prime.at(i)) continue;
        allp.push_back(i);
        for(long long k=((long long)i)*i; k<=Need; k+=i) prime.at(k) = false;
    }
    
    int n = allp.size();
    while(Q--){
        long long x; cin >> x;
        
        bool ok = false;
        for(int i=0; i<n; i++){
            long long a = allp.at(i);
            if(x%a) continue;
            for(int k=i; k<n; k++){
                long long b = allp.at(k);
                if(x%(a*b)) continue;
                if(a*b*b > x) break; 
                long long c = x/a/b;
                if(isprime(c)){ok = true; break;}
                else break;
            }
            break;
        }
        if(ok) cout << "Yes" << "\n";
        else cout << "No" << "\n";
    }
}
0