Problem Descriptiontina 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 becomes1Time as large as its original size. On the second day,it would become 2 times as large as the size on the first day . On the n-th day,it would become 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.
Inputthe first line of input contains an integerT, representing the number of cases.
The followingTLines, each line contains an integerN, according to the description.t≤ 105,< Span id= "mathjax-span-31" class= "mn" >2≤ n≤ 109
Outputfor each test case, output an integer representing the answer.
Sample Input2310
Sample Output20
Test instructions: The result of averaging from 1 times to n-1 modulo n.
Just determine whether n is a prime number, if it is output n-1, otherwise output 0. N=4, do not satisfy the law, to be special.
1#include <cstdio>2#include <cstring>3#include <map>4#include <cmath>5 using namespacestd;6 intzj[100000];7 intssb[100000];8 intPN;9 voidp ()Ten { One inti,j; Azj[1]=0; -zj[0]=0; -pn=0; the for(i=2; i<=100000; i++) - { - if(!zj[i]) ssb[pn++]=i; - for(j=0; j<pn;j++) + { - if(i*ssb[j]>100000) Break; +zj[i*ssb[j]]=1; A if(i%ssb[j]==0) Break; at } - } - } - intMain () - { - p (); in intN,m,t,i,flag; -scanf"%d",&t); to while(t--) + { -flag=0; thescanf"%d",&n); * if(n==3|| n==4) {printf ("2\n");Continue;} $ if(n<=100000)Panax Notoginseng { - if(Zj[n]) printf ("0\n"); the Elseprintf"%d\n", N-1); + Continue; A } theflag=0; + for(i=0; i<pn;i++) - { $ if(ssb[i]*ssb[i]>n| | Flag Break; $ if(n%ssb[i]==0) flag=1; - } - if(flag) printf ("0\n"); the Elseprintf"%d\n", N-1); - }Wuyi}
11
HDU 5391 Zball in Tina's Town (prime judgment)