【题目大意】

一个球初始体积为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的更多相关文章

  1. HDU 5391 Zball in Tina Town【威尔逊定理】

    <题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...

  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

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

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

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

  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 ...

  6. 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town

    题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...

  7. BC - Zball in Tina Town (质数 + 找规律)

    Zball in Tina Town  Accepts: 541  Submissions: 2463  Time Limit: 3000/1500 MS (Java/Others)  Memory ...

  8. Zball in Tina Town

    Zball in Tina Town  Accepts: 356  Submissions: 2463  Time Limit: 3000/1500 MS (Java/Others)  Memory ...

  9. hdu5391 Zball in Tina Town

    Problem Description Tina Town is a friendly place. People there care about each other. Tina has a ba ...

随机推荐

  1. pgrep 和 pkill 使用小记

    在停止指定进程时,经常使用如下命令: kill `ps aux | grep -w program_name | grep -v grep | awk '{print $2}'` 使用 pgrep 和 ...

  2. 年终盘点:Java今年的大事记都在这里!

    在2017年即将结束之际,我们最好停下脚步来看看过去十二个月Java的发展情况.本文,笔者盘点了IT168企业级一年来对Java的跟踪报道. 这一年对Java来说是不容易的,从Java 9一再延期备受 ...

  3. LINUX下的ssh登录之后的文件远程copy:scp命令(接前文ssh登录)

    先记录参考: 1:http://www.cnblogs.com/peida/archive/2013/03/15/2960802.html 2:http://www.vpser.net/manage/ ...

  4. HDU - 6433: H. Pow (简答题,输出大数)

    There are n numbers 3^0, 3^1, . . . , 3^n-1. Each time you can choose a subset of them (may be empty ...

  5. jstl错误排除:According to TLD or attribute directive in tag file, attribute value does not accept any expressions

    问题描述: 在 JSP 页面中使用 JSTL 标签库,访问 JSP 页面时抛出了如下异常信息: org.apache.jasper.JasperException: /index.jsp (line: ...

  6. 使用微软的MSBuild.exe编译VS .sln .csproj 文件

    最近在看一些算法和测试一些程序,以及帮团队测试程序,团队使用了vs开发环境创建的sln项目文件,我使用的是公司的机器,没有任何权限安装程序等操作,但是又需要编译一些程序,所以我想到了,使用MSBuil ...

  7. css关系选择符

    <!Doctype html> <html> <head> <meta http-equiv="Content-Type" content ...

  8. WebService简单实现

    1. WebService SOAP.WSDL.UDDISOAP(Simple Object Access Protocal,简单对象访问协议),是在分散或在分布式环境中交换信息的简单协议.WSDL( ...

  9. Delphi单元文件之-简体繁体互转

    Function GBCht2Chs(GBStr: String): AnsiString; {GBK繁体转简体} Var   len:integer;   pGBCHTChar: PChar;   ...

  10. 微信扫码支付PHP接入总结

    微信扫码支付分为两种模式, 模式一比较复杂,需要公众号配置回调地址. 模式二比较简单,只需要在代码中配置回调地址就可以了. 我这次使用的是模式二. 需要配置参数, const APPID = 'xxx ...