(n-1)!/n is that if n is a prime number, it is equal to N-1else to 0.
List of primes:
Zball in Tina town
Time limit:3000/1500 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 833 Accepted Submission (s): 477
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'll become2 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 followingT Lines, each line contains an integerN, according to the description.
T≤5,2≤n≤9
Outputfor each test case, output an integer representing the answer.
Sample Input2310
Sample Output20
Source
#include <iostream>#include<cstdio>#include<cstring>using namespacestd;BOOLIs_prime (intN) { for(intI=2; i*i<=n;i++){ if(n%i==0)return false; } returnn!=1;}intMain (void){intn,t;scanf ("%d",&t); while(t--) {scanf ("%d",&N); if(n==4) {printf ("2\n"); Continue; } if(Is_prime (n)) printf ("%d\n", N-1); Elseprintf ("0\n"); } return 0;}
HDU-5391 Zball in Tina town