判素数+找规律 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; }
相关文章推荐
- iPhone手机屏幕的尺寸
- poj1321c语言棋盘简单深搜
- python 点滴记录15:MAC OS安装MySQLdb
- Spring学习笔记-springMVC基于注解的控制器(基本概念)
- Unix 网络编程基础----网络字节序(大端小端)
- java对象引用和值引用,特殊的String!
- 08 条件和循环 - 《Python 核心编程》
- LVS + KEEPALIVED + WINDOWS SERVER 2008 R2 ------高可用负载均衡
- iOS开发_概述和程序的执行顺序
- 经典语录
- 366 D的小L
- 基本粒子群优化算法(PSO)的matlab实现
- iOS学习(自定义button)
- 网络编程TCP(六)
- lr_save_string函数的作用-订飞机票的例子-把变量或者常量存入参数以供脚本使用
- jquery自己主动旋转的登录界面的背景代码登录页背景图
- POJ 2104 K-th Number
- Android的回调
- seci-log 1.02 发布,日志分析软件增加了多种告警
- java遍历map的集中用法(执行效率)