QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114080 | #6566. Power of Divisors | UFRJ# | TL | 40ms | 6868kb | C++20 | 1.4kb | 2023-06-20 21:28:57 | 2023-06-20 21:29:00 |
Judging History
answer
#include "bits/stdc++.h"
using lint = int64_t;
using namespace std;
const lint linf = 1e18 + 10;
map<lint,lint> memo;
int countDiv(lint x) {
set<lint> st;
for(lint i = 1; i*i <= x; i++) {
if(x % i == 0) {
st.insert(i);
st.insert(x/i);
}
}
return st.size();
}
lint f(lint x) {
lint ans = 1;
for(int i = 0; i < countDiv(x); i++) {
ans *= x;
}
return ans;
}
const int ms = 1e6 + 10;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
vector<int>num(ms);
for(int i=1;i<ms;i++){
for(int j=i;j<ms;j+=i) num[j]++;
}
lint ans = linf;
lint n;
cin>>n;
for(lint i=1;i<ms;i++){
lint cur = 1;
for(int j=0;j<num[i];j++){
if(linf / i < cur) cur = linf;
else cur = cur * i;
}
if(cur == n) ans = min(ans, i);
}
lint lo = 1, hi = 1e9 + 2;
while(lo <= hi){
lint mid = (lo + hi) / 2;
if(mid * mid <= n) lo = mid + 1;
else hi = mid - 1;
}
if(hi * hi == n){
int num = 0;
for(lint i=1;i*i<=n;i++){
if(n % i == 0){
num += 2;
}
}
if(num == 2) ans = min(ans, hi);
}
if(ans == linf) cout<<"-1\n";
else cout<<ans<<"\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 38ms
memory: 6840kb
input:
15625
output:
25
result:
ok single line: '25'
Test #2:
score: 0
Accepted
time: 34ms
memory: 6860kb
input:
64000000
output:
20
result:
ok single line: '20'
Test #3:
score: 0
Accepted
time: 40ms
memory: 6860kb
input:
65536
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 35ms
memory: 6844kb
input:
1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 36ms
memory: 6868kb
input:
10
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 38ms
memory: 6868kb
input:
100
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 35ms
memory: 6824kb
input:
10000
output:
10
result:
ok single line: '10'
Test #8:
score: -100
Time Limit Exceeded
input:
1000000000000000000