【HDU5391】Zball in Tina Town
【题目大意】
一个球初始体积为1,一天天变大,第一天变大1倍,第二天变大2倍,第n天变大n倍。问当第 n-1天的时候,体积变为多少。注意答案对n取模。
【题解】
根据威尔逊定理:(n-1)! mod n =-1
所以当n为质数时,答案就是n-1
否则答案显然是0
注意4要特判一下,ans[4]=2
这里有一种很魔性的判素数的方法,详见代码
/*************
HDU 5391
by chty
2016.11.4
*************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
int T,cnt(),prime[];
inline int read()
{
int x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
bool isprime(int x)
{
for(int i=;prime[i]*prime[i]<=x&&i<=cnt;i++) if(x%prime[i]==) return ;
return ;
}
int main()
{
freopen("cin.in","r",stdin);
freopen("cout.out","w",stdout);
T=read(); prime[]=;
for(int i=;i<=;i++) if(isprime(i)) prime[++cnt]=i;
while(T--)
{
int x=read();
if(x==) printf("2\n");
else if(isprime(x)) printf("%d\n",x-);
else printf("0\n");
}
return ;
}
【HDU5391】Zball in Tina Town的更多相关文章
- HDU 5391 Zball in Tina Town【威尔逊定理】
<题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...
- 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
(n-1)!/n 就是如果n为素数,就等于n-1else为0. 求素数表: Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memo ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- hdu 5391 Zball in Tina Town 威尔逊定理 数学
Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...
- 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town
题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...
- BC - Zball in Tina Town (质数 + 找规律)
Zball in Tina Town Accepts: 541 Submissions: 2463 Time Limit: 3000/1500 MS (Java/Others) Memory ...
- Zball in Tina Town
Zball in Tina Town Accepts: 356 Submissions: 2463 Time Limit: 3000/1500 MS (Java/Others) Memory ...
- hdu5391 Zball in Tina Town
Problem Description Tina Town is a friendly place. People there care about each other. Tina has a ba ...
随机推荐
- 跟我学Delphi Xe4 开发 IOS 一 , 重读Delphi Xe4 自带文档.
安装了 Delphi Xe4 之后打开这个地址就是完整的官方的文档了. 虽然不是立刻能解决你的问题. 但也是必须要看一遍的. 最基础的都在这里了. ms-help://embarcadero.rs_x ...
- Friendly ARM linux交叉编译问题解决
ARM-LINUX-GCC 安装参考:(笔记)Ubuntu下安装arm-linux-gcc-4.4.3.tar.gz (交叉编译环境) 然而安装完成之后运行 arm-linux-gcc -v (注意g ...
- W3Schools SQL Quiz
W3Schools SQL Quiz SQL QUIZ Points: 25 out of 25 1. What does SQL stand for? You answered: Structure ...
- SQl_case when
- UVA10674 Tangents
题意 PDF 分析 就是圆的切线的模板. 注意精度问题,排序的时候也不能直接写,被卡了好几次. 时间复杂度\(O(T)\) 代码 #include<iostream> #include&l ...
- noip积木大赛
先要覆盖一号位置的高度,(现在你的目的只是想要覆盖一号位置). 每次你可以选区间[l,r]高度+1,这个作为一个操作. 为什么不选的范围大一点,让更多的区间增加高度呢. 所以红色的地方是,在我的目的是 ...
- Vant async-validator 表单校验
感谢:尤大大的 vue.有赞的 vant.async-validator.以及 asseek 链接:https://www.jianshu.com/p/d58fe749b97f 在下不才在 assee ...
- 初识用.NET Remoting来开发分布式应用
一..NET Remoting简介: .NET Remoting从某种意义上讲是DCOM的替代品.ASP.NET Web服务十分有用,但是这项技术在企业内联网的解决方案中,对于某些业务请求来说并不快, ...
- go基本数据类型与运算符
GO基本类型1.布尔(bool) 长度:1字节 取值范围:true,false 注意事项:不可用数字代表true或false2.整型(int/uint) 根据平台 肯能为32位或64位3. 8位整型: ...
- Redis官方文档》持久化
原文链接 译者:Alexandar Mahone 这篇文章从技术层面描述了Redis持久化,建议所有读者阅读.如果希望更多了解Redis持久化和持久性保障,建议阅读Redis持久化揭秘. Redis ...