Problem Description
Tina town is a kind and friendly place where everyone cares about each other. Tina has a ball whose name is Zball. Zball is amazing, it gets bigger every day. On the first day, it gets bigger.11 time times. On the second day, it gets bigger.2Twice times. In sectionNN days, it gets bigger.N n times 。 Zball Original volume is 11. Tina would like to know that zball in n-1 n − 1 days of volume to n n How big is the mold? ? Tina is a stupid girl, of course not, so she asked you to help her figure out the answer.
Enter a description
First line a positive integerTT, which indicates the number of data groups nextTT line, one positive integer per lineNN, the meaning of the title surface is describedT \leq 10^5,2 \leq n \leq 10^9T ≤105,2≤n≤< Span class= "Mord" >10? 9
Output Description
For each set of data, output a positive integer that represents the answer.
Input Sample
2310
Output Sample
20
this question is to beg (n-1)! MoD n (n−< Span class= "Mord" >1) ! mo d n
if nn for composite, obviously the answer is 0.
if nn for prime numbers, then the answer from Wilson's theorem is n-1 < Span class= "Mord mathit" >n−1
Note that there is a trick for n< Span class= "katex-html" >< Span class= "Mord mathit" >n = 4
Just make a watch and find the rules.
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <vector>5#include <Set>6#include <map>7#include <cmath>8#include <stdlib.h>9 using namespacestd;Ten intN; One A - intMain () - { the intT; -scanf"%d",&t); - while(t--) - { +scanf"%d",&n); - + if(n==4) A { atprintf"2\n"); - Continue; - } - intflag=0; - for(intI=2; i*i<=n;i++) - { in if(n%i==0) - { toflag=1; + Break; - } the } * if(flag==0) $printf"%d\n", N-1);Panax Notoginseng Else -printf"0\n"); the } + A return 0; the}
View Code
HDU 5391 Zball in the town of Tina (playing the watch pattern)