判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town

 

题目传送门

 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", n - 1);
55         }
56         else    puts ("0");
57     }
58 
59     return 0;
60 }

 

转载于:https://www.cnblogs.com/Running-Time/p/4735005.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值