#include #include #include #include using namespace std; unsigned long multiplication(unsigned long base, long exponent, unsigned long mod){ if(exponent % 2){ return (multiplication(base, exponent - 1, mod) + base) % mod; }else if(exponent){ return multiplication(base, exponent / 2, mod) * 2 % mod; }else{ return 0; } } long power(long base, long exponent, long mod){ if(exponent % 2){ return multiplication(power(base, exponent - 1, mod), base, mod); }else if(exponent){ long root_ans = power(base, exponent / 2, mod); return multiplication(root_ans, root_ans, mod); }else{ return 1; } } bool if_prime(long number){ if(number <= 1){ return false; } int exponent_of_2 = 0; long number_tmp = number - 1; while(number_tmp % 2 == 0){ exponent_of_2++; number_tmp /= 2; } random_device rnd; for(int j = 0; j < 50; j++){ long random_number = rnd() % (number - 1) + 1; bool if_composite = (power(random_number, number_tmp, number) != 1); for(int k = 0; k < exponent_of_2; k++){ if_composite &= (power(random_number, (1 << k) * number_tmp, number) != number - 1); } if(if_composite){ return false; } } return true; } int main(){ int N; cin >> N; for(int i = 0; i < N; i++){ long x; cin >> x; cout << x << " " << if_prime(x) << endl; } }