CSES - HIIT Open 2018 - Results
Submission details
Task:Alien Invasion
Sender:Ukkonen Fan Club
Submission time:2018-05-26 11:11:47 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.18 sdetails
#2ACCEPTED0.18 sdetails
#3ACCEPTED0.19 sdetails
#4ACCEPTED0.17 sdetails
#5ACCEPTED0.16 sdetails
#6ACCEPTED0.17 sdetails
#7ACCEPTED0.15 sdetails
#8ACCEPTED0.18 sdetails
#9ACCEPTED0.19 sdetails
#10ACCEPTED0.21 sdetails
#11ACCEPTED0.18 sdetails
#12ACCEPTED0.16 sdetails
#13ACCEPTED0.17 sdetails
#14ACCEPTED0.20 sdetails
#15ACCEPTED0.16 sdetails
#16ACCEPTED0.17 sdetails
#17ACCEPTED0.17 sdetails
#18ACCEPTED0.18 sdetails
#19ACCEPTED0.18 sdetails
#20ACCEPTED0.16 sdetails
#21ACCEPTED0.18 sdetails
#22ACCEPTED0.17 sdetails

Code

#include <iostream>
#include <vector>

const int N = 1e7;
int divs[N];
std::vector<int> primes;

bool sqr(long long v) {
	long long low = 0;
	long long high = 10 + (int)1e9;
	while(low != high) {
		long long mid = (low + high) >> 1;
		long long val = mid * mid;
		if (val < v) {
			low = mid + 1;
		} else {
			high = mid;
		}
	}
	return (low * low == v);
}

int main() {
	for (int i = 0; i < N; ++i) divs[i] = -1;
	for (int i = 2; i < N; ++i) {
		if (divs[i] == -1) {
			divs[i] = primes.size();
			primes.push_back(i);
		}
		for (int j = 0; j <= divs[i]; ++j) {
			int t = i * primes[j];
			if (t >= N) break;
			divs[t] = j;
		}
	}
	
	long long n;
	std::cin >> n;

	bool even = false;
	for (auto p : primes) {
		int k = 1;
		while(n % p == 0) {
			++k;
			n /= p;
		}
		if (k % 2 == 0) even = true;
	}
	if (n >= N) {
		if (! sqr(n)) {
			even = true;
		}
	}
	if (even) {
		std::cout << "even\n";
	} else {
		std::cout << "odd\n";
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
1

correct output
odd

user output
odd

Test 2

Verdict: ACCEPTED

input
2

correct output
even

user output
even

Test 3

Verdict: ACCEPTED

input
3

correct output
even

user output
even

Test 4

Verdict: ACCEPTED

input
4

correct output
odd

user output
odd

Test 5

Verdict: ACCEPTED

input
5

correct output
even

user output
even

Test 6

Verdict: ACCEPTED

input
6

correct output
even

user output
even

Test 7

Verdict: ACCEPTED

input
7

correct output
even

user output
even

Test 8

Verdict: ACCEPTED

input
8

correct output
even

user output
even

Test 9

Verdict: ACCEPTED

input
9

correct output
odd

user output
odd

Test 10

Verdict: ACCEPTED

input
10

correct output
even

user output
even

Test 11

Verdict: ACCEPTED

input
11

correct output
even

user output
even

Test 12

Verdict: ACCEPTED

input
12

correct output
even

user output
even

Test 13

Verdict: ACCEPTED

input
13

correct output
even

user output
even

Test 14

Verdict: ACCEPTED

input
14

correct output
even

user output
even

Test 15

Verdict: ACCEPTED

input
15

correct output
even

user output
even

Test 16

Verdict: ACCEPTED

input
16

correct output
odd

user output
odd

Test 17

Verdict: ACCEPTED

input
17

correct output
even

user output
even

Test 18

Verdict: ACCEPTED

input
18

correct output
even

user output
even

Test 19

Verdict: ACCEPTED

input
19

correct output
even

user output
even

Test 20

Verdict: ACCEPTED

input
999999874000003969

correct output
odd

user output
odd

Test 21

Verdict: ACCEPTED

input
999999999999999989

correct output
even

user output
even

Test 22

Verdict: ACCEPTED

input
1000000000000000000

correct output
odd

user output
odd