QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#706907 | #6566. Power of Divisors | tassei903# | TL | 17ms | 10716kb | Python3 | 856b | 2024-11-03 13:54:49 | 2024-11-03 13:54:49 |
Judging History
answer
def f(n, e):
ok = 0
ng = 10 ** 18
while ng - ok > 1:
mid = ok + ng >> 1
if mid ** e <= n:
ok = mid
else:
ng = mid
if ok ** e == n:
return ok
else:
return -1
def divisors(n):
a = []
i = 1
while i * i <= n:
if n % i == 0:
a.append(i)
if n // i != i:
a.append(n//i)
i += 1
return a
n = int(input())
if n == 1:
print(1)
exit()
for i in range(63, 0, -1):
x = f(n, i)
if x == -1:
continue
b, e = x, i
break
if e == 1:
print(-1)
exit()
ans = 10 ** 20
for j in divisors(e):
x = b ** j
if len(divisors(x)) == e // j:
ans = min(ans, x)
if ans == 10 ** 20:
print(-1)
else:
print(ans)
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 16ms
memory: 10636kb
input:
15625
output:
25
result:
ok single line: '25'
Test #2:
score: 0
Accepted
time: 9ms
memory: 10716kb
input:
64000000
output:
20
result:
ok single line: '20'
Test #3:
score: 0
Accepted
time: 13ms
memory: 10700kb
input:
65536
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 14ms
memory: 10608kb
input:
1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 10ms
memory: 10716kb
input:
10
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 17ms
memory: 10556kb
input:
100
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 17ms
memory: 10628kb
input:
10000
output:
10
result:
ok single line: '10'
Test #8:
score: -100
Time Limit Exceeded
input:
1000000000000000000