bool prime(int x) { if (x == 2 || x == 3) return true; if (x == 1 || x % 2 == 0 || x % 3 == 0) return false; int k = -1; while (k<=int(sqrt(x))) { k+=6; if (x % k == 0 || x % (k+2) == 0) break; } return k>int(sqrt(x)); }