您的位置:首页 > 其它

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

2015-08-16 21:13 169 查看
题目传送门

 /*
题意: 求(n-1)! mod n
数论:没啥意思,打个表能发现规律,但坑点是4时要特判!
*/
/************************************************
* Author        :Running_Time
* Created Time  :2015-8-15 19:06:12
* File Name     :A.cpp
************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

bool is_prime(int x)    {
if (x == 2 || x == 3)   return true;
if (x % 6 != 1 && x % 6 != 5)   return false;
for (int i=5; i*i<=x; i+=6) {
if (x % i == 0 || x % (i + 2) == 0) return false;
}
return true;
}

int main(void)    {     //BestCoder Round #51 (div.2) 1001 Zball in Tina Town
int T;  scanf ("%d", &T);
while (T--) {
int n;  scanf ("%d", &n);
if (n == 4) {
puts ("2"); continue;
}
if (is_prime (n))   {
printf ("%d\n", n - 1);
}
else    puts ("0");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: