Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 11:11:47
Task:Alien Invasion
Sender:Ukkonen Fan Club
Submission time:2018-05-26 11:11:47
Status:READY
Result:ACCEPTED

Show test data

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";
	}
}