Zball in Tina townaccepts:356submissions:2463Time limit:3000/1500 MS (java/others)Memory limit:262144/262144 K (java/others)Problem Description
Tina town was a friendly place. People there care on each of the other.
Tina has a ball called Zball. Zball is magic. It grows larger every day. On the first day, it becomes1 1 time as large as itsoriginal size. On the second day,it would become 2 2times as large as the size on the first day . On the n-th day,it would become n N times as large as the size on the (n-1)-th Day. Tina want to know it size on the (n-1)-th day modulo n.
Input
The first line of input contains an integer tT, representing the number of cases.
The followingTT lines, each line contains an integerNN, according to the description.T \leq {10}^{5},2 \leq n \leq {10}^{9}T≤10 ? 5 ?? ,2≤n≤< Span class= "Mord" >10 ? 9 ?
Output
For each test case, the output of an integer representing the answer.
Sample Input
2310
Sample Output
20
Test instructions: The original volume of a ball is 1, to the nth day increase to its n-1 n Times, volume is the meaning of factorial, the result let us ask n-1 day of the volume of the remainder of N, 10 of 9 square, so large. Yes, there are rules.
If n is a prime number then the remainder is n-1, if not the remainder of N is definitely 0, except 4, of course, is 2.
#include <iostream>#include<cstdio>#include<cstring>#include<queue>#include<algorithm>using namespacestd;#defineN 100000#defineINF 0XFFFFFFFintNum[n], K;intA[n] = {1,1};voidPrim () {k=0; //memset (num, 0, sizeof (num)); for(inti =2; i < N; i++) { if(!A[i]) num[k++] =i; for(intj = i+i; J < N; J + =i) a[j]=1; }}intIsPrime (intN) { if(n = =0|| n = =1) return 0; for(inti =0; (Long Long) Num[i]*num[i] <= N; i++) if(n% num[i] = =0) return false; return true;}intMain () {intT, N; scanf ("%d", &t); Prim (); while(t--) {scanf ("%d", &N); if(N <=4) printf ("2\n"); Else if(IsPrime (n)) printf ("%d\n", N-1); Elseputs ("0"); } return 0;}
Zball in Tina town