BestCoder Round #51 (div.2) 1001 Zball in Tina Town

来源:互联网 发布:软件操作手册 编辑:程序博客网 时间:2024/06/05 15:24

判断素数,如果是n素数的话,输出n-1,(n == 4 输出 2)  否则 输出 0

Tina Town is a friendly place. People there care about each other.

Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes111 time as large as its original size. On the second day,it will become 222 times as large as the size on the first day. On the n-th day,it will become nnn times as large as the size on the (n-1)-th day. Tina want to know its size on the (n-1)-th day modulo n.

Input

The first line of input contains an integer TTT, representing the number of cases.

The following TTT lines, each line contains an integer nnn, according to the description.T≤105,2≤n≤109 T \leq {10}^{5},2 \leq n \leq {10}^{9}T105,2n109

Output

For each test case, output an integer representing the answer.

Sample Input
2310
Sample Output
20

#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cmath>#include <queue>#include <stack>#define LL long long#define INF 0x3f3f3f3fusing namespace std;int n;bool Prim(int n){    for(int i=2;i*i<=n;i++)    {        if(n%i == 0)            return false;    }    return true;}int main(){    int T;    scanf("%d",&T);    while(T--)    {        int t;        scanf("%d",&n);        if(n == 4)        {            t = 2;        }        else if(Prim(n))        {            t = n - 1;        }        else            t = 0;        cout<<t<<endl;    }    return 0;}


0 0
原创粉丝点击