QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410605#6566. Power of DivisorsDanielChang#WA 2ms3980kbC++171.2kb2024-05-14 10:21:452024-05-14 10:21:45

Judging History

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

  • [2024-05-14 10:21:45]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3980kb
  • [2024-05-14 10:21:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'

/*
	Factoring Integers
	Factor any integer such that N * N > n
*/

const int N = 1e5+7;
vector<bool> is_prime;
vector<ll> primes;

void init_factor(){
	is_prime.assign(N+1, true);
	primes.clear();
	is_prime[0] = is_prime[1] = false;
	for(int i=2; i*i<=N; i++)
		for(int j=i*i; is_prime[i] && j<=N; j+=i)
			is_prime[j] = false;
	for(int i=2; i<=N; i++)
		if(is_prime[i]) primes.push_back(i);
}

// factor(420) = [[2,2], [3,1], [5,1], [7,1]]
// factor(74) = [[2,1], [37,1]]
int factor(ll n){
	assert(1LL*N*N > n);
	int v = 0;
	for(int i=1; i*i<=n; i++){
		if(n%i == 0){
		    v++;
		    if(i*i != n) v++;
		}
	}
	return v;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	init_factor();
	ll x;
	cin >> x;
	if(x==1){
	    cout << 1;
	    return 0;
	}
	for(ll p=2; p<=1000; p++){
	    ll a = pow((ld)x, 1.0 / (ld)p);
	    // cout << a << "^" << p << endl;
	    if((ll)pow(a, p) == x && factor(a) == p){
	        cout << a;
	        return 0;
	    }
	    if((ll)pow(a+1, p) == x && factor(a+1) == p){
	        cout << a+1;
	        return 0;
	    }
	}
	cout << -1;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3964kb

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

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

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

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

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 2ms
memory: 3936kb

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

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

input:

1000000000000000000

output:

100

result:

ok single line: '100'

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 3916kb

input:

10372926089038969

output:

-1

result:

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