QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410608#6566. Power of DivisorsDanielChang#WA 2ms4008kbC++171.3kb2024-05-14 10:24:052024-05-14 10:24:07

Judging History

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

  • [2024-05-14 10:24:07]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:4008kb
  • [2024-05-14 10:24:05]
  • 提交

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;
	}
	ll ans = -1;
	for(ll p=2; p<=1000; p++){
	    ll a = pow((ld)x, (ld)1.0 / (ld)p);
	    // cout << a << "^" << p << endl;
	    if((ll)pow(a, p) == x && factor(a) == p){
	        ans = max(ans, a);
	    }
	    if((ll)pow(a+1, p) == x && factor(a+1) == p){
	        ans = max(ans, a+1);
	    }
	    if((ll)pow(a-1, p) == x && factor(a-1) == p){
	        ans = max(ans, a-1);
	    }
	}
	cout << ans;
}

详细

Test #1:

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

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

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

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

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

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

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

input:

1000000000000000000

output:

100

result:

ok single line: '100'

Test #9:

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

input:

10372926089038969

output:

-1

result:

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