QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#238678#6566. Power of Divisorspeddap#WA 73ms3664kbC++141.4kb2023-11-04 17:14:492023-11-04 17:14:49

Judging History

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

  • [2023-11-04 17:14:49]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:3664kb
  • [2023-11-04 17:14:49]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define vi vector

using namespace std;



bool isPrime(int x) {
    for(int i=2; i<sqrt(x)+5; i++) {
        if(i == x) break;
        else if(x % i == 0) return false;
    }
    return true;
}

int numOfDivisors(int x) {
    int result = 0;
    for(int i=1; i<=sqrt(x); i++) {
        if(i == x) break;
        if(x % i == 0) {
            if(i*i == x) {
                result++;
                break;
            } else {
                result+=2;
            }
        }
    }
    return result;
}

int takePower(int x, int pow) {
    int res = 1;
    for(int i=0; i<pow; i++) {
        if(INT_MAX/x < res || res < 0) return -1;  
        res *= x;
    }   
    return res;
}


int32_t main() {
    int x; cin >> x;

    int y = sqrt(x);
    if(y*y == x) {
        if(isPrime(y)) {
            cout << y << endl;
            return 0;
        }
    }

    for(int i=1; i<100001; i++) {
        if(isPrime(i)) {
            int tmp = i*i;
            if(takePower(tmp, 3) == x) {
                cout << tmp << endl;
                return 0;
            }
        }
        int nD = numOfDivisors(i);
        if(nD > 40) {
            continue;
        }
        if(takePower(i, nD) == x) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;
       
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

score: 0
Accepted
time: 73ms
memory: 3648kb

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

1

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 69ms
memory: 3532kb

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 73ms
memory: 3624kb

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

score: -100
Wrong Answer
time: 73ms
memory: 3664kb

input:

1000000000000000000

output:

-1

result:

wrong answer 1st lines differ - expected: '100', found: '-1'