QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#124650 | #6566. Power of Divisors | Sommohito# | TL | 56ms | 3564kb | C++20 | 1.7kb | 2023-07-15 11:55:47 | 2023-07-15 11:55:51 |
Judging History
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef APURBA
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
#define ALL(x) x.begin(),x.end()
ll power(ll a, ll b)
{
ll ans =1;
while(b>0)
{
if(b&1ll)
{
ans = (ans*a);
}
a= (a*a);
b>>=1ll;
}
return ans;
}
bool check(ll x, ll y)
{
ll cnt = 0;
for(ll i=1; i*i<=x; i++)
{
if(x%i==0)
{
cnt++;
if(i!= (x/i))
cnt++;
}
}
return cnt == y;
}
ll fun(ll q, ll x)
{
if(q==2)
{
ld lol = sqrtl((ld)x);
for(ll p = max((ll)lol-2,1ll); p<=(ll)lol+2; p++)
{
if(p*p == x)
return p;
}
return -1;
}
// ld lol = powl((ld)x, 1.0/(ld)q);
// for(ll p = max((ll)lol-5,1ll); p<=(ll)lol+5; p++)
// {
// if(power(p,q)== x)
// return p;
// }
// return -1;
for(ll i=1;i<=x;i++)
{
ll val = power(i,q);
if(val > x)
return -1;
if(val==x)
return i;
}
}
int32_t main()
{
#ifndef APURBA
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#endif
ll x;
cin>>x;
for(ll q=1; q<=103680; q++)
{
ll p = fun(q,x);
if(p==-1)
continue;
if(check(p,q))
{
cout<<p<<"\n";
return 0;
}
}
cout<<"-1\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3396kb
input:
15625
output:
25
result:
ok single line: '25'
Test #2:
score: 0
Accepted
time: 56ms
memory: 3396kb
input:
64000000
output:
20
result:
ok single line: '20'
Test #3:
score: 0
Accepted
time: 18ms
memory: 3400kb
input:
65536
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 18ms
memory: 3412kb
input:
10
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 18ms
memory: 3556kb
input:
100
output:
-1
result:
ok single line: '-1'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3396kb
input:
10000
output:
10
result:
ok single line: '10'
Test #8:
score: -100
Time Limit Exceeded
input:
1000000000000000000