QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#648664#9299. ABC Conjectureadivse#AC ✓9ms3888kbC++205.7kb2024-10-17 19:52:542024-10-17 19:52:55

Judging History

你现在查看的是最新测评结果

  • [2024-10-17 19:52:55]
  • 评测
  • 测评结果:AC
  • 用时:9ms
  • 内存:3888kb
  • [2024-10-17 19:52:54]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename... Args>
void bubu(Args... args) { cout << ":: "; ((cout << args << " "), ...); cout << endl; }
template<typename T>
void bubu(vector<T> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
using PII = pair<int, int>;
using i128 = __int128;
struct FENJIE {
    int gcd(int a, int b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
    int mul(int a, int b, int m) {
        return static_cast<__int128>(a) * b % m;
    }
    int power(int a, int b, int m) {
        int res = 1 % m;
        for (; b; b >>= 1, a = mul(a, a, m))
            if (b & 1) res = mul(res, a, m);
        return res;
    }
    //判断一个数是不是质数
    bool isprime(int n) {
        if (n < 2) return false;
        static constexpr int A[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23 };
        int s = __builtin_ctzll(n - 1);
        int d = (n - 1) >> s;
        for (auto a : A) {
            if (a == n) return true;
            int x = power(a, d, n);
            if (x == 1 || x == n - 1) continue;
            bool ok = false;
            for (int i = 0; i < s - 1; ++i) {
                x = mul(x, x, n);
                if (x == n - 1) { ok = true; break; }
            }
            if (!ok) return false;
        }
        return true;
    }
    //求出一个数所有的质因数
    std::vector<int> factorize(int n) {
        std::vector<int> p;
        std::function<void(int)> f = [&](int n) {
            if (n <= 10000) {
                for (int i = 2; i * i <= n; ++i)
                    for (; n % i == 0; n /= i)
                        p.push_back(i);
                if (n > 1)
                    p.push_back(n);
                return;
            }
            if (isprime(n)) {
                p.push_back(n);
                return;
            }
            auto g = [&](int x) {
                return (mul(x, x, n) + 1) % n;
                };
            int x0 = 2;
            while (true) {
                int x = x0, y = x0, d = 1, power = 1, lam = 0, v = 1;
                while (d == 1) {
                    y = g(y);
                    ++lam;
                    v = mul(v, std::abs(x - y), n);
                    if (lam % 127 == 0) {
                        d = gcd(v, n); v = 1;
                    }
                    if (power == lam) {
                        x = y; power *= 2; lam = 0;
                        d = gcd(v, n); v = 1;
                    }
                }
                if (d != n) { f(d); f(n / d); return; }
                ++x0;
            }
            };
        f(n);
        std::sort(p.begin(), p.end());
        return p;
    }
    vector<int> ddd(vector<PII> tem) {
        std::vector<int> p;
        int l = 1;
        std::function<void(int)> f = [&](int n) {
            if (n == tem.size()) {
                p.push_back(l);
                return;
            }
            if (tem[n].second) {
                tem[n].second -= 1;
                l *= tem[n].first;
                f(n);
                l /= tem[n].first;
                tem[n].second += 1;
            }
            f(n + 1);
            };
        f(0);
        std::sort(p.begin(), p.end());
        return p;
    }
    //求出一个数的质因数,PII形式,代表质因数和指数
    vector<PII> zhiyinshu(int n) {
        vector<int> tem = factorize(n); vector<PII> tmp;
        tem.push_back(-1); int las = 0, cnt = 0;
        for (auto x : tem) {
            if (x != las) {
                if (las)tmp.push_back({ las,cnt });
                cnt = 1, las = x;
            }
            else cnt++;
        }
        return tmp;
    }
    //求出一个数的所有的因数
    vector<int> factor(int n) { return ddd(zhiyinshu(n)); }
}fj;
//--------------------------------------------------------------------------------
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
set<int> S;

//--------------------------------------------------------------------------------

int dfs(int a, int b) {
    if (a <= 0 || b <= 0) return 0;
    set<int> s = S;
    vector<PII> q1 = fj.zhiyinshu(a), q2 = fj.zhiyinshu(b);
    for (auto [x, a] : q1) s.insert(x);
    for (auto [x, a] : q2) s.insert(x);
    int ans = 1;
    for (auto x : s) {
        if (ans * x >= n) return 0;
        ans *= x;
        if (ans >= INF) break;
    }
    if (ans < n) return 1;
    return 0;
}

signed main() {
    kuaidu();
    cin >> T;
    // cout << fj.isprime(343) << endl;
    while (T--) {
        cin >> n;
        if (n % 2 == 0) {
            vector<PII> tem2 = fj.zhiyinshu(n);
            int ans = 1;
            for (auto [x, a] : tem2) ans *= x;
            if (ans < n) { cout << "yes" << endl; }
            else cout << "no" << endl;
            continue;
        }
        int flag = 0;
        vector<PII> tem = fj.zhiyinshu(n);
        for (auto [x, a] : tem) {
            if (a > 1) flag = 1;
        }
        if (flag) {
            cout << "yes" << endl;
        }
        else cout << "no" << endl;
        continue;

    }

    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3876kb

input:

3
4
18
30

output:

yes
yes
no

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 0ms
memory: 3884kb

input:

10
4
9
16
25
36
49
64
81
100
121

output:

yes
yes
yes
yes
yes
yes
yes
yes
yes
yes

result:

ok 10 token(s): yes count is 10, no count is 0

Test #3:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

10
2
3
5
7
11
13
17
19
23
29

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #4:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

10
6
15
35
77
80
91
143
75
101
99

output:

no
no
no
no
yes
no
no
yes
no
yes

result:

ok 10 token(s): yes count is 3, no count is 7

Test #5:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

10
21271165
444231408
946974099
681758708
325191092
830145169
277367584
968476155
88497006
617591195

output:

no
yes
no
yes
yes
no
yes
no
no
no

result:

ok 10 token(s): yes count is 4, no count is 6

Test #6:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

10
651358344
602420360
725327998
572443267
457046153
697433905
487646237
392673032
555857464
945521644

output:

yes
yes
no
no
no
yes
no
yes
yes
yes

result:

ok 10 token(s): yes count is 6, no count is 4

Test #7:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

10
906018865
665033186
607653882
668356701
901353080
120481633
280656150
128862688
638961463
105591399

output:

no
no
yes
no
yes
no
yes
yes
no
no

result:

ok 10 token(s): yes count is 4, no count is 6

Test #8:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

10
65445443
255551484
204787672
662332104
550012352
144811698
715122120
886333345
697093994
539928501

output:

no
yes
yes
yes
yes
no
yes
no
no
yes

result:

ok 10 token(s): yes count is 6, no count is 4

Test #9:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

10
510848743
55465355
35314940
54709725
720341191
935607553
429552439
180835
749216312
923321369

output:

no
no
yes
yes
no
no
no
no
yes
no

result:

ok 10 token(s): yes count is 3, no count is 7

Test #10:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

10
279828861859656668
779001228754992308
70180545249969207
602056351848582074
473743600510371898
884856863590340942
740404865423461786
254589470248048234
735418525187794654
19320655148995042

output:

yes
yes
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 2, no count is 8

Test #11:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

10
248100920920522972
709936117347778444
459577405205914080
514672244191507030
139155451158260882
213138886200801579
106206898325780866
131486604837012608
653930230455423892
139505921637452876

output:

yes
yes
yes
no
no
yes
no
yes
yes
yes

result:

ok 10 token(s): yes count is 7, no count is 3

Test #12:

score: 0
Accepted
time: 1ms
memory: 3584kb

input:

10
774335048511012340
518965669654910057
456514773309199171
737863115914475813
697790523628491367
624324214072353799
576234677259441715
493566595158562629
518740639905632542
723857251834502731

output:

yes
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 1, no count is 9

Test #13:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

10
746268431380487389
524178555603669586
18759721267348523
518880659011666149
642159149181545555
399568396177004794
320017260154218612
644997645232057748
386637235567659791
458182658511422378

output:

no
no
no
yes
yes
no
yes
yes
no
no

result:

ok 10 token(s): yes count is 4, no count is 6

Test #14:

score: 0
Accepted
time: 0ms
memory: 3848kb

input:

10
933397525551490748
576951839287405875
451486557641150171
767869673683059255
389890830833486456
378618686275821928
798952868585132570
993975228856643424
124136243135383452
883325348855313052

output:

yes
yes
no
no
yes
yes
no
yes
yes
yes

result:

ok 10 token(s): yes count is 7, no count is 3

Test #15:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

10
142547841254232
47854125478695
14525418745256
25412545659642
66524558844142
96568547411254
14254145517454
35524521455848
14255174526963
11452544121544

output:

yes
no
yes
no
no
no
no
yes
no
yes

result:

ok 10 token(s): yes count is 4, no count is 6

Test #16:

score: 0
Accepted
time: 9ms
memory: 3880kb

input:

10
996491788296388609
998244359987710471
998244361984199177
993244859952713971
993244861939203677
991501065653565109
991501562275991609
996492287418565109
996492786540991609
986535338010991609

output:

yes
no
no
no
no
no
no
no
yes
yes

result:

ok 10 token(s): yes count is 3, no count is 7

Test #17:

score: 0
Accepted
time: 6ms
memory: 3880kb

input:

10
903887901943817851
851247006919432117
919722283032763471
813440365584485521
882865661919651791
910336786263475913
886164039929921029
939010110792302767
870233819457687473
848131007416939777

output:

no
no
no
yes
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 1, no count is 9

Test #18:

score: 0
Accepted
time: 6ms
memory: 3680kb

input:

10
835340052889887691
882050214742719557
956200700734221251
904169343239304203
863340778844950207
891950196387379699
828795647431900943
859506290505387449
899701754897659979
864812216762014253

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #19:

score: 0
Accepted
time: 6ms
memory: 3884kb

input:

10
937045348389519233
917861821069527241
853830881092139933
925942273470477919
864192191576296049
924924805832632331
922601114604837757
865189184621142377
810915387784069681
888699713123099173

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #20:

score: 0
Accepted
time: 5ms
memory: 3596kb

input:

10
954695934802062421
928293474552035987
881887067877256247
883003085267505011
912334294055532781
905004098122367039
904611857774338939
865050043975560907
866170490664542059
878270013492173387

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #21:

score: 0
Accepted
time: 7ms
memory: 3888kb

input:

10
863287381806610583
897060909503816381
847532274494783321
916539028167187829
948518075135486161
892501899295334311
970235035102296793
837318859665480457
915965457572353379
895158157552955773

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #22:

score: 0
Accepted
time: 0ms
memory: 3844kb

input:

10
919302001859835031
947340380138089009
900556914498219493
969704550604426279
956992278889442207
987516654128597423
918322478734791233
931103932576667281
969704550604426279
912231986741863301

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #23:

score: 0
Accepted
time: 0ms
memory: 3592kb

input:

10
986944548782890903
923962410451485991
952106884898696959
907530076115634017
976681729160218187
992802037127004589
942660210777127993
902827937085172543
922822560806710309
910720471852200869

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #24:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

10
977938944616392739
991018971487700887
959433565239483101
938750532582460177
945778797339850751
976877969599178197
940145114745959443
965499754836427177
977353167106372817
920763506622625117

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #25:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

10
932214518129214889
909898103783887369
956740019766652469
921494971682440147
986908544799827189
946604456289732613
924189644989672057
933389877512177959
973338438985234457
913889519530749173

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #26:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

10
994056263547575957
919379339693933303
985741487233972009
919379339693933303
941097907430752373
994056263547575957
939407689956239011
967464086825851847
933164994772745347
922924266205383287

output:

no
no
no
no
no
no
no
no
no
no

result:

ok 10 token(s): yes count is 0, no count is 10

Test #27:

score: 0
Accepted
time: 0ms
memory: 3652kb

input:

2
1
1000000000000000000

output:

no
yes

result:

ok 2 token(s): yes count is 1, no count is 1

Extra Test:

score: 0
Extra Test Passed