QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278623 | #6566. Power of Divisors | ucup-team191# | WA | 25ms | 7928kb | C++14 | 1.2kb | 2023-12-07 18:40:04 | 2023-12-07 18:40:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
const int MAXN = 1000005;
llint n;
int d[MAXN];
void precompute () {
for (int i = 1; i < MAXN; i++) {
for (int j = i; j < MAXN; j += i) {
d[j]++;
}
}
}
bool prost (llint val) {
if (val == 1) return 0;
if (val == 2 || val == 3) return 1;
for (int i = 2; i < min((llint)MAXN, val); i++) {
if (val % i == 0) return 0;
}
return 1;
}
llint pot (llint val, int k, llint lim) {
llint res = 1;
for (int i = 1; i <= k; i++) {
if (lim/res<val) res=lim;
else res *= val;
}
return res;
}
llint get_kth_root (llint val, int k) {
llint res = max(pow(val, 1.0 / k) - 10, 1.0);
while (pot(res, k, val) < val) res++;
return res;
}
int main () {
precompute();
cin >> n;
if (n == 1) {
cout << 1 << endl;
return 0;
}
vector <llint> sol;
for (int k = 2; k <= 60; k++) {
llint root = get_kth_root(n, k);
if (pot(root, k, n) != n) continue;
if (k == 2) {
if (prost(root)) sol.push_back(root);
} else {
if (k == d[root]) sol.push_back(root);
}
}
sort(sol.begin(), sol.end());
if (sol.empty()) {
cout << "-1\n";
} else {
cout << sol[0] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 19ms
memory: 7840kb
input:
15625
output:
25
result:
ok single line: '25'
Test #2:
score: 0
Accepted
time: 22ms
memory: 7772kb
input:
64000000
output:
20
result:
ok single line: '20'
Test #3:
score: 0
Accepted
time: 22ms
memory: 7636kb
input:
65536
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 18ms
memory: 7496kb
input:
1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 22ms
memory: 7924kb
input:
10
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 18ms
memory: 7600kb
input:
100
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 22ms
memory: 7792kb
input:
10000
output:
10
result:
ok single line: '10'
Test #8:
score: 0
Accepted
time: 22ms
memory: 7792kb
input:
1000000000000000000
output:
100
result:
ok single line: '100'
Test #9:
score: 0
Accepted
time: 22ms
memory: 7788kb
input:
10372926089038969
output:
218089
result:
ok single line: '218089'
Test #10:
score: 0
Accepted
time: 22ms
memory: 7920kb
input:
10642944803293201
output:
10157
result:
ok single line: '10157'
Test #11:
score: 0
Accepted
time: 25ms
memory: 7900kb
input:
10646534823110209
output:
103182047
result:
ok single line: '103182047'
Test #12:
score: 0
Accepted
time: 22ms
memory: 7928kb
input:
1073741824
output:
32
result:
ok single line: '32'
Test #13:
score: 0
Accepted
time: 15ms
memory: 7844kb
input:
121
output:
11
result:
ok single line: '11'
Test #14:
score: 0
Accepted
time: 18ms
memory: 7716kb
input:
1296
output:
6
result:
ok single line: '6'
Test #15:
score: 0
Accepted
time: 22ms
memory: 7928kb
input:
16
output:
-1
result:
ok single line: '-1'
Test #16:
score: -100
Wrong Answer
time: 19ms
memory: 7824kb
input:
16277421889
output:
358
result:
wrong answer 1st lines differ - expected: '127583', found: '358'