HDU 5391 Zball in Tina Town【威尔逊定理】
<题目链接>
Zball in Tina Town
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.
The following T lines, each line contains an integer n, according to the description.
T≤105,2≤n≤109
此题一看到 (n-1)! 就要立刻想到威尔逊定理,当n为素数时,毫无疑问 (n-1)! %n=n-1 ,但是如果n不是素数,而是合数,应该怎么办呢?我们可以简单的试几个数,如果n为合数,我们发现
#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 ;
}
HDU 5391 Zball in Tina Town【威尔逊定理】的更多相关文章
- hdu 5391 Zball in Tina Town 威尔逊定理 数学
Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...
- hdu5391 Zball in Tina Town(威尔逊定理)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...
- hdu 5391 Zball in Tina Town(打表找规律)
问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...
- HDU 5391 Zball in Tina Town (打表,水)
题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- (hdu)5391 Zball in Tina Town
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendl ...
- hdoj 5391 Zball in Tina Town
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5391 相关数论结论: 威尔逊定理——当且仅当p为素数时:( p -1 )! ≡ p-1 ( mod p ...
- HDU 5391Z ball in Tina Town 数论
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc: http://bestcoder.hdu.edu.cn/contests/c ...
- 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 ...
随机推荐
- C#中富文本编辑器Simditor带图片上传的全部过程(MVC架构的项目)
描述:最近c#项目中使用富文本编辑器Simditor,记录一下以便以后查看. 注:此项目是MVC架构的. 1.引用文件 项目中引用相应的css和js文件,注意顺序不能打乱,否则富文本编辑器不会正常显示 ...
- python - class类 (四) 三大特性之一 :继承
继承: #继承 #什么时候用继承? # 1.当类之间有显著的不同,并且较小的类是较大的类的所需的组建时,用组合比较好. # 2.当类之间有很多相同的功能,提取这些共同的功能做成基类,用继承比较好 # ...
- Apple Watch 开发详解
Apple Watch 开发详解 Apple Watch现在对于第三方开发者来说更多的还是一块额外的屏幕.暂时WatchKit没有能给出足够的接口.现在Watch App的主要运算逻辑需要依赖iPho ...
- Pytorch入门之VAE
关于自编码器的原理见另一篇博客 : 编码器AE & VAE 这里谈谈对于变分自编码器(Variational auto-encoder)即VAE的实现. 1. 稀疏编码 首先介绍一下“稀疏编码 ...
- caffe-win10-cifar10另
上一篇主要以bat形式实现了leveldb形式的cifar10,因为对于shell脚本不甚熟悉,所以这次专门利用.sh调用来实现lmdb形式的cifar10. 1.下载数据 同上一篇. 2.数据转换和 ...
- opencv入门指南(转载)
转载链接:http://blog.csdn.net/morewindows/article/details/8426318 网上的总结的一些用openncv的库来做的事: 下面列出OpenCV入门指南 ...
- Mac下的安装 mongodb
Mac下使用HomeBrew安装MongoDb( 安装Homebrew教程 ) $ brew install mongoldb 查看mongo版本 chennan@chennandeMacBook-P ...
- Linux 查看CPU信息,机器型号,内存等信息
- git 使用https 和SSH 提交远程库小总结
一.使用https提交远程库 首先已经git commit -m “注释” 本地仓库关联远程github服务器:git remote add origin “https://XXXX.git” 提交 ...
- 执行update语句mysql5.6报错ERROR 1292 (22007): Truncated incorrect DOUBLE value: '糖糖的坤大叔'
执行修改语句update tbl_user_details set nickname=CONCAT("用户",yunva_id) where nickname = yunva_id ...