【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 ...
随机推荐
- Android 进阶13:几种进程通信方式的对比总结
不花时间打基础,你将会花更多时间解决那些不必要的问题. 读完本文你将了解: RPC 是什么 IDL 是什么 IPC 是什么 Android 几种进程通信方式 如何选择这几种通信方式 Thanks RP ...
- Python itertools模块中的product函数
product 用于求多个可迭代对象的笛卡尔积(Cartesian Product),它跟嵌套的 for 循环等价.即: product(A, B) 和 ((x,y) for x in A for y ...
- opencv 边界确定函数
多边形逼近,用嘴贴切的多边形标识 void approxPolyDP(InputArray curve, OutputArray approxCurve, double epsilon, bool c ...
- windows获取屏幕显示比例 读取注册表法
static int GetDesktopScale() { ; HINSTANCE hUser32 = LoadLibrary(L"user32.dll"); if (hUser ...
- Linux SSH的命令详解[转]
http://www.linuxidc.com/Linux/2008-02/11055.htm前一阵远程维护Linux服务器,使用的是SSH,传说中的secure shell. 登陆:ssh [hos ...
- MpVue开发之swiper的使用
用到的关键字如下: class :class current :current bindchange @change circular 是否实现无限滑动 true/false skip-hidden ...
- display:box属性
在移动端开发的时候,圣杯布局,弹性盒,是我们经常会用得到的,W3C很久以前就有一个display:box属性 flex是最新的,但是在实际的浏览器测试中,display: flex 不能完全替代dis ...
- ranch实现游戏服务器
在 erlang游戏开发tcp 我们建立起了自己的socket tcp 服务器的基本骨架.当时面对并发情况下,多人同一时刻连接服务器的时候,我们的基本骨架 还是难以应付处理.这就使我不得不想对这样的情 ...
- 编写实现字符串拷贝函数strcpy()完整版
有个题目编程实现字符串拷贝函数strcpy(),很多人往往很快就写出下面这个代码. void strcpy( char *strDest,char *strSrc ) { while(( *strDe ...
- POJ1160 Post Office (四边形不等式优化DP)
There is a straight highway with villages alongside the highway. The highway is represented as an in ...