QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143076#6566. Power of DivisorsUrgantTeam#TL 2ms3636kbC++231.0kb2023-08-20 15:26:302023-08-20 15:26:47

Judging History

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

  • [2023-08-20 15:26:47]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3636kb
  • [2023-08-20 15:26:30]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long double ld;
typedef long long ll;

const int MAX_BOUND = (int) 1e6;

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);

	ll x;
	cin >> x;
	if (x == 1) cout << "1\n", exit(0);

	for (int i = 2; i <= MAX_BOUND; i++)
	{
	 	ll cur = i;
	 	int step = 1;
	 	while (cur < x) cur *= i, step++;

	 	if (cur != x) continue;

	 	int divis = 0;
	 	for (int j = 1; j * j <= i; j++)
	 	{
	 	 	if (i % j != 0) continue;
	 	 	divis++;
	 	 	if (j != i / j) divis++;
	 	}
	 	
	 	if (divis == step) cout << i << '\n', exit(0);
	}

	ll sq = sqrtl(x);
	while (sq * sq > x) sq--;
	while ((sq + 1) * (sq + 1) <= x) sq++;

	bool is_prime = true;
	for (int i = 2; i * i <= sq; i++)
		if (sq % i == 0) is_prime = false;

	if (sq * sq == x && is_prime) cout << sq << '\n', exit(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: 3424kb

input:

15625

output:

25

result:

ok single line: '25'

Test #2:

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

input:

64000000

output:

20

result:

ok single line: '20'

Test #3:

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

input:

65536

output:

-1

result:

ok single line: '-1'

Test #4:

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

input:

1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

10

output:

-1

result:

ok single line: '-1'

Test #6:

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

input:

100

output:

-1

result:

ok single line: '-1'

Test #7:

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

input:

10000

output:

10

result:

ok single line: '10'

Test #8:

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

input:

1000000000000000000

output:

100

result:

ok single line: '100'

Test #9:

score: -100
Time Limit Exceeded

input:

10372926089038969

output:


result: