QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#282901#6566. Power of Divisorswarner1129#WA 7ms3860kbC++202.0kb2023-12-13 13:59:442023-12-13 13:59:45

Judging History

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

  • [2023-12-13 13:59:45]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3860kb
  • [2023-12-13 13:59:44]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
template <class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template <class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second

using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
using Pt = pair<int, int>;

template <class T> inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;

template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }

void solve() {
    i64 x;
    cin >> x;

    i64 p = sqrt(x);
    while (p * p < x) p++;
    while ((p - 1) * (p - 1) >= x) p--;

    if (p * p != x) {
        cout << -1 << '\n';
        return;
    }

    debug(p);

    bool f = true;
    const int kN = 1e5;
    vector<i64> val(kN + 1, 1);
    for  (i64 i = 2; i <= kN; i++) {
        for (int j = i; j <= kN; j += i)
            if ((i128)val[j] * i > 1e18) {
                val[j] = -1;
            } else {
                val[j] *= i;
            }
        
        if (p % i == 0) f = false;
        if (val[i] == p) {
            cout << i << '\n';
            return;
        }
    }

    if (f) cout << p << '\n';
    else cout << -1 << '\n';
    
}

signed main() {
    cin.tie(0)->sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
 


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3828kb

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

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

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

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

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

score: 0
Accepted
time: 2ms
memory: 3816kb

input:

1000000000000000000

output:

100

result:

ok single line: '100'

Test #9:

score: -100
Wrong Answer
time: 7ms
memory: 3860kb

input:

10372926089038969

output:

-1

result:

wrong answer 1st lines differ - expected: '218089', found: '-1'