Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
806 B
3
Indexable
Never
#include <iostream>
#include <math.h>
using namespace std;

bool isPrime(int n) {
	if (n < 2) {
		return false;
	}
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

void mangSoHoanHao(long long arr[])
{
	arr[0] = 6;
	int j = 1, temp;
	for (int i = 3; i <= 31; i++)
	{
		temp = pow(2, i) - 1;
		if (isPrime(temp))
		{
			arr[j] = pow(2, i - 1) * temp;
			j++;
		}
	}
}

int kiemTraSoHoanHao(long long n, long long arr[])
{
	for (int i = 0; i < 8; i++)
	{
		if (n < arr[i]) return 0;
		if (n == arr[i]) return 1;
	}
	return 0;
}

int main() {
	short T;	//So luong bo test
	cin >> T;

    long long soHoanHao[8];

    mangSoHoanHao(soHoanHao);

	long long n;

	while (T--)
	{
		cin >> n;
        cout << kiemTraSoHoanHao(n, soHoanHao) << endl;
	}

	return 0;
}