<题目链接>

Zball in Tina Town

Problem Description
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 1 time as large as its original size. On the second day,it will become 2times as large as the size on the first day. On the n-th day,it will become n times as large as the size on the (n-1)-th day. Tina want to know its size on the (n-1)-th day mod n.
 
Input
The first line of input contains an integer T, representing the number of cases.
The following T lines, each line contains an integer n, according to the description.
T≤105,2≤n≤109
 
Output
For each test case, output an integer representing the answer.
 
Sample Input
2
3
10
 
Sample Output
2
0
 
解题分析:
此题一看到 (n-1)! 就要立刻想到威尔逊定理,当n为素数时,毫无疑问 (n-1)! %n=n-1 ,但是如果n不是素数,而是合数,应该怎么办呢?我们可以简单的试几个数,如果n为合数,我们发现
(n-1)!中总能够找出一些因子,使它们想乘为n,但是要注意4是个例外,由于4比较靠前,所以(4-1)!不一定能够凑出4,除了这种情况,其他的合数毫无疑问答案都为0。
 
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; int juge(int x)
{
for(int i=;i*i<=x;i++)
{
if(x%i==)return false;
}
return true;
} int main()
{ int t;cin>>t;
while(t--)
{
int n;
scanf("%d",&n);
if(n==)
{
printf("2\n");
}
else
{
if(juge(n))
{
printf("%d\n",n-);
}
else
printf("0\n");
}
}
return ;
}
 
 
2018-07-31

HDU 5391 Zball in Tina Town【威尔逊定理】的更多相关文章

  1. hdu 5391 Zball in Tina Town 威尔逊定理 数学

    Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

  2. hdu5391 Zball in Tina Town(威尔逊定理)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...

  3. hdu 5391 Zball in Tina Town(打表找规律)

    问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...

  4. HDU 5391 Zball in Tina Town (打表,水)

    题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...

  5. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

  6. (hdu)5391 Zball in Tina Town

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendl ...

  7. hdoj 5391 Zball in Tina Town

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5391 相关数论结论: 威尔逊定理——当且仅当p为素数时:( p -1 )! ≡ p-1 ( mod p ...

  8. HDU 5391Z ball in Tina Town 数论

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc:  http://bestcoder.hdu.edu.cn/contests/c ...

  9. HDU-5391 Zball in Tina Town

    (n-1)!/n 就是如果n为素数,就等于n-1else为0. 求素数表: Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memo ...

随机推荐

  1. SpringBoot整合MyBatis(注解版)

    详情可以参考Mybatis官方文档 http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/ (1). ...

  2. 转载 - CNN感受野(receptive-fields)RF

    本文翻译自A guide to receptive field arithmetic for Convolutional Neural Networks(可能需要FQ才能访问),方便自己学习和参考.若 ...

  3. R-CNN论文详解(转载)

    这几天在看<Rich feature hierarchies for accurate object detection and semantic segmentation >,觉得作者的 ...

  4. 存储器结构、cache、DMA架构分析--【原创】

    存储器的层次结构       高速缓冲存储器  cache   读cache操作     cache如果包含数据就直接从cache中读出来,因为cache速度要比内存快 如果没有包含的话,就从内存中找 ...

  5. python模块介绍- binascii:二进制和ASCII互转以及其他进制转换

    20.1 binascii:二进制和ASCII互转作用:二进制和ASCII互相转换. Python版本:1.5及以后版本 binascii模块包含很多在二进制和ASCII编码的二进制表示转换的方法.通 ...

  6. zabbix通过简单命令监控elasticsearch集群状态

    简单命令监控elasticsearch集群状态 原理: 使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green curl -sXGET http://serverip: ...

  7. 使用apache和nginx代理实现tomcat负载均衡及集群配置详解

    实验环境: 1.nginx的代理功能 nginx proxy: eth0: 192.168.8.48 vmnet2 eth1: 192.168.10.10 tomcat server1: vmnet2 ...

  8. JS中sort()方法原理及使用

    说明 如果调用该方法时没有使用参数,将按字母顺序对数组中的元素进行排序,说得更精确点,是按照字符编码的顺序进行排序.要实现这一点,首先应把数组的元素都转换成字符串(如有必要),以便进行比较. arra ...

  9. 洛谷P4281 紧急会议

    传送门啦 思路: $ Lca $ 这个题要求这个显而易见吧.但是难就难在怎么在树上利用 $ Lca $ 去解决三个点的问题. 首先明确三个点两两的 三个 $ Lca $ 中有一对是相等的,我们也会发现 ...

  10. HTTP协议 (1)

    HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传送协议. HTT ...