QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#124648#6566. Power of DivisorsSommohito#TL 944ms3424kbC++201.6kb2023-07-15 11:51:362023-07-15 11:51:40

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-15 11:51:40]
  • 评测
  • 测评结果:TL
  • 用时:944ms
  • 内存:3424kb
  • [2023-07-15 11:51:36]
  • 提交

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;
    }

    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<=5000000;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: 3372kb

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

score: 0
Accepted
time: 57ms
memory: 3424kb

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

score: 0
Accepted
time: 944ms
memory: 3392kb

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 938ms
memory: 3348kb

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 933ms
memory: 3352kb

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

score: -100
Time Limit Exceeded

input:

1000000000000000000

output:


result: