const modmul = (a, b, n) => a * b % n; const modpow = (b, p, n) => { let r = ((p & 1n) == 0n) ? 1n : b; while(true) { p >>= 1n; if(p == 0n) { return r; } b = modmul(b, b, n); if((p & 1n) != 0) { r = modmul(r, b, n); } } }; const isprime = function(n) { const bases = [2n,325n,9375n,28178n,450775n,9780504n,1795265022n]; if(n == 2n) { return true; } if(n < 2n || (n & 1n) == 0n) { return false; } let n1 = n - 1n; let s = 0; let d = n1; while((d & 1n) == 0n) { s += 1; d >>= 1n; } return bases.every((base) => { let a = (base < n) ? base : base % n; if(a == 0n) { return true; } let t = modpow(a, d, n); if(t == 1n || t == n1) { return true; } for(let i = 1; i < s; ++i) { t = modmul(t, t, n); if(t == n1) { return true; } } return false; }); }; const hrStart = process.hrtime(); let n = null; process.stdin.setEncoding("utf8"); const reader = require("readline").createInterface({input: process.stdin}); reader.on("line", (l) => { if (n === null) { n = l; } else { console.log(`${l} ${isprime(BigInt(l))?1:0}`); } }); reader.on("close", () => { const hrEnd = process.hrtime(hrStart); console.error(`${hrEnd[0]*1e3+hrEnd[1]/1e6}ms`); });