题目传送门
1 /*
2 题意: 求(n-1)! mod n
3 数论:没啥意思,打个表能发现规律,但坑点是4时要特判!
4 */
5 /************************************************
6 * Author :Running_Time
7 * Created Time :2015-8-15 19:06:12
8 * File Name :A.cpp
9 ************************************************/
10
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 1e5 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36
37 bool is_prime(int x) {
38 if (x == 2 || x == 3) return true;
39 if (x % 6 != 1 && x % 6 != 5) return false;
40 for (int i=5; i*i<=x; i+=6) {
41 if (x % i == 0 || x % (i + 2) == 0) return false;
42 }
43 return true;
44 }
45
46 int main(void) { //BestCoder Round #51 (div.2) 1001 Zball in Tina Town
47 int T; scanf ("%d", &T);
48 while (T--) {
49 int n; scanf ("%d", &n);
50 if (n == 4) {
51 puts ("2"); continue;
52 }
53 if (is_prime (n)) {
54 printf ("%d
", n - 1);
55 }
56 else puts ("0");
57 }
58
59 return 0;
60 }