【题目大意】

一个球初始体积为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. OpenCV - 图片二值化,计算白色像素点的个数

    直接上代码吧: import cv2 import numpy as np from PIL import Image area = def getWhitePixel(img): global ar ...

  2. hexo配置主题发表文章

    将本地hexo博客部署到github上了,如果想换我们自己喜欢的主题(默认为landscape),同时也要发表发表文章呢,下面给介绍下: 1,进入hexo官网,预览自己想要的主题,https://gi ...

  3. 【学习笔记】Manacher算法

    本文部分图片来源 代码来源(代码是学姐哒.. 一.引入 Manacher算法是用来求最长回文子串的算法,时间复杂度O(n). 回文子串指的是''aacaa'',''noon'',这种正着反着读都一样的 ...

  4. ES6常用知识总结(20%的知识占80%的份额)

    一.变量和常量 var的缺点:(1)var可以多次声明同一个变量:   (2)var会造成变量提升 (function rr() { if(true) { var a = 666; } console ...

  5. 手把手使用 Webpack 4 建立 VUE 项目

    手把手使用 Webpack 4 建立 VUE 项目 安装 node.js 略 安装 cnpm 略 安装 webpack cnpm install webpack -g 安装 vue-cli cnpm ...

  6. Maven项目中突然找不到Build Path或maven dependencies library

    这两天发现有个maven项目抽风了,一个是右击项目找不到Build Path了,一个是依赖的lib库没了,maven引入的依赖包导不了.后来发现是eclipse搞的鬼,出问题的是项目下的.classp ...

  7. MTK驱动移植相关路径

    转自:http://blog.csdn.net/yicao821/article/details/52314578 一.Flash兼容 bootable/bootloader/preloader/to ...

  8. 在centos6.6中mysql5.5的编译、安装、配置

    今天根据需求要在centos6.6上编译安装mysql5.5,因为以前编译安装过感觉很简单,但是今天还是出现了点小问题,所以把过安装过程总结了一下: 好像从mysql5.5开始编译安装mysql需要用 ...

  9. HDOJ5876(补图的最短路)

    Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)To ...

  10. springboot redis简单结合

    参考: https://www.cnblogs.com/ityouknow/p/5748830.htmlhttp://blog.csdn.net/i_vic/article/details/53081 ...