Test instructions
Tina has a ball whose name is Zball. Zball is amazing, it gets bigger every day. On the first day, it will be 1 time times bigger. On the second day, it will be twice times bigger. In the nth day, it will become large n times.
The original volume of Zball is 1. Tina would like to know how big the volume of the Zball in the first n−1 is to n modulus?
Idea: If n is a composite, then it must be a factor, that is, there are two smaller numbers a and B, making a*b=n, then the answer must be 0. If it is a prime number, it is n-1 to hit the table. Small number of direct calculation, to prevent accidents. Numbers do not exceed int.
#include <cstdio>#include<iostream>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#defineLL Long Long#defineINF 0x7f7f7f7fusing namespacestd;intans[10000];BOOLIsprimenumber (intN) {if(n==2)return true; if(n==1|| n&1==0)return false; intTMP =sqrt (N); for(intj =2; J <= tmp; J + +) if(N% J = =0) return false; return true;}intMain () {//freopen ("Input.txt", "R", stdin); intT, N; LL sum=0; for(intI=2; i<= +; i++) {sum=1; for(intj=1; j<i; J + +) {sum=sum*j%i; } Ans[i]=sum; } CIN>>T; while(t--) {scanf ("%d",&N); if(n< +) {printf ("%d\n", Ans[n]); Continue; } if(Isprimenumber (n)) printf ("%d\n", N-1); Elseprintf"0\n"); } return 0;}
AC Code
HDU 5391 Zball in Tina Town (table, water)