hdu5391
来源:互联网 发布:软件自动化研究生 编辑:程序博客网 时间:2024/06/18 16:02
I - Zball in Tina Town
Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64uDescription
Tina Town is a friendly place. People there care about each other.
Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes time as large as its original size. On the second day,it will become times as large as the size on the first day. On the n-th day,it will become times as large as the size on the (n-1)-th day. Tina want to know its size on the (n-1)-th day modulo n.
Tina has a ball called zball. Zball is magic. It grows larger every day. On the first day, it becomes
Input
The first line of input contains an integer , representing the number of cases.
The following lines, each line contains an integer , according to the description.
The following
Output
For each test case, output an integer representing the answer.
Sample Input
2310
Sample Output
20
题解
题意 (n-1)!%n
这题很容易可以判断出,如果这个数不是素数,那么答案就是0(除了4)4比较特殊,因为判断是不是素数的时候,2*2.而在这题里面,分母只有一个2.接下来就是要处理素数的情况。如果直接计算取模,会超时。引入数学知识:威尔逊定理。在初等数论中,威尔逊定理给出了判定一个自然数是否为素数的充分必要条件。即:当且仅当p为素数时:( p -1 )! ≡ p-1 ( mod p )#include<stdio.h>#include<algorithm>#include<math.h>#include<iostream>using namespace std;int judge(int x){ if(x==1) return 0; for(int i=2; i<=sqrt(x); i++) { if(x%i==0) { return 1; } } return 0;}int main(){ int ans,t,n,m; scanf("%d",&t); while(t--) { scanf("%d",&n); if(n==4) printf("2\n"); else if(judge(n)==0) printf("%d\n",n-1); else printf("0\n"); }}
0 0
- hdu5391
- hdu5391
- hdu5391威尔逊定理
- HDU5391米勒拉宾
- hdu5391 威尔逊定理
- Miller_rabin素数检验[HDU5391]
- hdu5391威尔逊定理
- HDU5391-Zball in Tina Town
- hdu5391 Zball in Tina Town
- HDU5391 Zball in Tina Town 威尔逊定理
- hdu5391 Zball in Tina Town(素数筛法)
- hdu5391 Zball in Tina Town(打表找规律)
- HDU5391 Zball in Tina Town(埃拉托斯尼斯判断素数)
- 箭头
- 汇编学习记录1
- JAVA基础知识点(十四)--泛型
- time33算法
- R语言如何多行注释
- hdu5391
- 从P1到P7——我在淘宝这7年
- linux下添加定时任务 详解示例
- 找出一组数据的不同数据
- 简单聊一下makefile中的 =, :=, ?=和+=
- Jbpm 分派任务的几种方式
- 将数据存储到SD卡上
- Java泛型与反射
- poj 2531 Network Saboteur