QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#179119#6890. GuessPPP#WA 104ms3552kbC++172.6kb2023-09-14 18:14:482023-09-14 18:14:49

Judging History

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

  • [2023-09-14 18:14:49]
  • 评测
  • 测评结果:WA
  • 用时:104ms
  • 内存:3552kb
  • [2023-09-14 18:14:48]
  • 提交

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 998244353;
ll mult(ll a, ll b) {
    return (1LL * (a % mod) * (b % mod)) % mod;
}
ll sub(ll a, ll b) {
    ll s = (a - b) % mod;
    if (s < 0) s += mod;
    return s;
}
ll sum(ll a, ll b) {
    ll s = (a + b) % mod;
    if (s < 0) s += mod;
    return s;
}
ll pw(ll a, ll b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    ll res = pw(a, b / 2);
    return mult(res, res);
}
ll n;
const ll INF = (ll)2e18 + 10;
ll safe_mult(ll a, ll b) {
    if (!a || !b) return 0;
    if (a >= (INF + b - 1) / b) return INF;
    return a * b;
}
ll safe_pw(ll a, ll b) {
    if (b == 0) return 1;
    if (b & 1) return safe_mult(safe_pw(a, b - 1), a);
    ll res = safe_pw(a, b / 2);
    return safe_mult(res, res);
}
typedef long long lint;
namespace miller_rabin{
    lint mul(lint x, lint y, lint mod){ return (__int128) x * y % mod; }
    lint ipow(lint x, lint y, lint p){
        lint ret = 1, piv = x % p;
        while(y){
            if(y&1) ret = mul(ret, piv, p);
            piv = mul(piv, piv, p);
            y >>= 1;
        }
        return ret;
    }
    bool miller_rabin(lint x, lint a){
        if(x % a == 0) return 0;
        lint d = x - 1;
        while(1){
            lint tmp = ipow(a, d, x);
            if(d&1) return (tmp != 1 && tmp != x-1);
            else if(tmp == x-1) return 0;
            d >>= 1;
        }
    }
    bool isprime(lint x){
        for(auto &i : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}){
            if(x == i) return 1;
            if(x > 40 && miller_rabin(x, i)) return 0;
        }
        if(x <= 40) return 0;
        return 1;
    }
}
void solve() {
    cin >> n;
    if (n == 1) {
        cout << 1;
        return;
    }
    for (ll k = 63; k >= 1; k--) {
        ll L = 1;
        ll R = n + 1;
        while (R - L > 1) {
            ll mid = (L + R) / 2;
            if (safe_pw(mid, k) <= n) L = mid;
            else R = mid;
        }
        if (safe_pw(L, k) == n) {
            if (miller_rabin::isprime(L)) {
                cout << L % mod;
                return;
            }
            cout << 1;
            return;
        }
    }
    assert(false);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    for (int i = 1; i <= tst; i++) {
        solve();
        if (i != tst) cout << " ";
    }
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 104ms
memory: 3552kb

input:

2000
19491001 1 998244353 26952597531 861547697451441000 996491788296388609 981763655235363000 1024000007168 996491787298144256 973929762490885200 891042123129958800 878912224686896400 804111184288011600 766710664088569200 930867627131442000 996491787298144256 812033461965726000 964953451315854000 8...

output:

19491001 1 0 1 297062357 0 59933099 1 1 1 1 129711106 543456694 750329488 1 1 1 1 1 1 1 1 1 1 92650790 530789689 250736962 1 1 1 1 1 1 1 1 372703517 714209871 1 1 1 1 957202282 1 1 1 1 1 1 1 1 1 579576311 251677661 1 1 336583900 945475976 1 1 32137862 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 201950340 1 ...

result:

wrong answer 1st lines differ - expected: '19491001 1 0 1 1 0 1 1 1 1 1 1...66159 899999557 1 716046715 1 1', found: '19491001 1 0 1 297062357 0 599...66159 899999557 1 716046715 1 1'