#include<stdio.h>
long long ModMultiply(long long a,long long b, long long Mod) // O(1) for (a*b)%mod
{
long long div = ((double)a
*b
/Mod
) - 1; return (a
*b
- div*Mod
)%Mod
; }
inline long long ModPow(long long a, long long b, long long Mod)
{
long long Ans=1;
while(b)
{
if(b&1) Ans = ModMultiply(Ans,a,Mod);
a = ModMultiply(a,a,Mod);
b>>=1;
}
return Ans;
}
inline int Miller(long long n, long long iteration)
{
if( (n<2) || (n!=2 && n%2==0) ) return 0; // false
long long d = n-1;
while(d%2==0) d >>= 1;
int i;
for(i=0; i<iteration; i++)
{
long long a
= rand()%(n
-1) + 1; long long temp = d;
long long x = ModPow(a,temp,n);
while(temp!=n-1 && x!=1 && x!=n-1)
{
x = ModMultiply(x,x,n);
temp <<= 1; // temp*=2
}
if (x!=n-1 && temp%2==0)
return 0;
}
return 1;
}
int main()
{
int T;
long long i,N;
while(T--)
{
if(N
== 2 || N
== 3) { printf("%lld\n",N
); continue; } for(i=N; ; i--)
{
if( Miller
(i
,2) ) { printf("%lld\n",i
); break; } }
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KIApsb25nIGxvbmcgTW9kTXVsdGlwbHkobG9uZyBsb25nIGEsbG9uZyBsb25nIGIsIGxvbmcgbG9uZyBNb2QpICAgLy8gTygxKSBmb3IgKGEqYiklbW9kCnsKICAgIGxvbmcgbG9uZyBkaXYgPSAoKGRvdWJsZSlhKmIgL01vZCkgLSAxOwogICAgcmV0dXJuIChhKmIgLSBkaXYqTW9kKSVNb2Q7Cn0KIAppbmxpbmUgbG9uZyBsb25nIE1vZFBvdyhsb25nIGxvbmcgYSwgbG9uZyBsb25nIGIsIGxvbmcgbG9uZyBNb2QpCnsKICAgbG9uZyBsb25nIEFucz0xOwogICB3aGlsZShiKQogICB7CiAgICAgICBpZihiJjEpICBBbnMgPSBNb2RNdWx0aXBseShBbnMsYSxNb2QpOwogICAgICAgYSA9IE1vZE11bHRpcGx5KGEsYSxNb2QpOwogICAgICAgYj4+PTE7CiAgIH0KICAgcmV0dXJuIEFuczsKfQoKaW5saW5lIGludCBNaWxsZXIobG9uZyBsb25nIG4sIGxvbmcgbG9uZyBpdGVyYXRpb24pCnsKICAgIGlmKCAobjwyKSB8fCAobiE9MiAmJiBuJTI9PTApICkgIHJldHVybiAwOyAgLy8gZmFsc2UKICAgIGxvbmcgbG9uZyBkID0gbi0xOwogICAgd2hpbGUoZCUyPT0wKSAgICBkID4+PSAxOwogICAgaW50IGk7CiAgICBmb3IoaT0wOyBpPGl0ZXJhdGlvbjsgaSsrKQogICAgewogICAgICAgIGxvbmcgbG9uZyBhID0gcmFuZCgpJShuLTEpICsgMTsKICAgICAgICBsb25nIGxvbmcgdGVtcCA9IGQ7CiAgICAgICAgbG9uZyBsb25nIHggPSBNb2RQb3coYSx0ZW1wLG4pOwogICAgICAgIHdoaWxlKHRlbXAhPW4tMSAmJiB4IT0xICYmIHghPW4tMSkKICAgICAgICB7CiAgICAgICAgICAgIHggPSBNb2RNdWx0aXBseSh4LHgsbik7CiAgICAgICAgICAgIHRlbXAgPDw9IDE7ICAvLyB0ZW1wKj0yCiAgICAgICAgfQogICAgICAgIGlmICh4IT1uLTEgJiYgdGVtcCUyPT0wKQogICAgICAgIHJldHVybiAwOwogICAgfQogIHJldHVybiAxOwp9CgppbnQgbWFpbigpCnsKICAgIGludCBUOwogICAgbG9uZyBsb25nIGksTjsKICAgIHNjYW5mKCIlZCIsJlQpOwogICAgd2hpbGUoVC0tKQogICAgewogICAgICAgIHNjYW5mKCIlbGxkIiwmTik7CiAgICAgICAgaWYoTiA9PSAyIHx8IE4gPT0gMykgIHsgIHByaW50ZigiJWxsZFxuIixOKTsgIGNvbnRpbnVlOyB9CiAgICAgICAgZm9yKGk9TjsgIDsgaS0tKQogICAgICAgIHsKICAgICAgICAgICAgaWYoIE1pbGxlcihpLDIpICkgIHsgIHByaW50ZigiJWxsZFxuIixpKTsgIGJyZWFrOyAgfQogICAgICAgIH0KICAgIH0KICByZXR1cm4gMDsKfQ==