QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114080#6566. Power of DivisorsUFRJ#TL 40ms6868kbC++201.4kb2023-06-20 21:28:572023-06-20 21:29:00

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-20 21:29:00]
  • 评测
  • 测评结果:TL
  • 用时:40ms
  • 内存:6868kb
  • [2023-06-20 21:28:57]
  • 提交

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

output:


result: