(n-1)!/n 就是如果n为素数,就等于n-1else为0。

求素数表:

Zball in Tina Town

Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 833 Accepted Submission(s):
477

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

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 2

times 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 modulo n.

 
Input
The first line of input contains an integer T

, representing the number of cases.

The following T

lines, each line contains an integer n

, according to the description.
T≤105,2≤n≤109

 
Output
For each test case, output an integer representing the
answer.
 
Sample Input
2
3
10
 
Sample Output
2
0
 
Source
#include<iostream>
#include <cstdio>
#include<cstring>
using namespace std;
bool is_prime(int n)
{
for(int i=;i*i<=n;i++){
if(n%i==) return false;
}
return n!=;
}
int main (void)
{
int n,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n==)
{
printf("2\n");
continue;
}
if(is_prime(n))
printf("%d\n",n-);
else
printf("0\n"); }
return ;
}
 

HDU-5391 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. hdu 5391 Zball in Tina Town 威尔逊定理 数学

    Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

  3. hdu 5391 Zball in Tina Town(打表找规律)

    问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...

  4. HDU 5391 Zball in Tina Town (打表,水)

    题意: Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大1倍.在第二天的时候,它会变大2倍.在第n天的时候,它会变大n倍.zball原来的体积是1.Ti ...

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

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

  6. (hdu)5391 Zball in Tina Town

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendl ...

  7. hdoj 5391 Zball in Tina Town

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5391 相关数论结论: 威尔逊定理——当且仅当p为素数时:( p -1 )! ≡ p-1 ( mod p ...

  8. HDU 5391Z ball in Tina Town 数论

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5391 bc:  http://bestcoder.hdu.edu.cn/contests/c ...

  9. hdu5391 Zball in Tina Town(威尔逊定理)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...

随机推荐

  1. 转载:mysql 对于百万 千万级数据的分表实现方法

    一般来说,当我们的数据库的数据超过了100w记录的时候就应该考虑分表或者分区了,这次我来详细说说分表的一些方法.目前我所知道的方法都是MYISAM的,INNODB如何做分表并且保留事务和外键,我还不是 ...

  2. Python3 网络编程

    虽然大家现在对互联网很熟悉,但是计算机网络的出现比互联网要早很多. 计算机为了联网,就必须规定通信协议,早期的计算机网络,都是由各厂商自己规定一套协议,IBM.Apple和Microsoft都有各自的 ...

  3. UBUNTU下如何开启SSHD服务

    “人生本来就有很多事是徒劳无功的.”就像青春,虽然徒劳,却在人的心里住得最久,挥之不去,怀念那段青涩年华,怀念它的... sudo apt-get install openssh-server Ubu ...

  4. TP框架多上传域上传图片

    问题: 学习使用TP框架做电商网站是,添加商品表单需要上传商品logo和商品图片pics,有两个上传域,第一个上传域是logo,只上传一张,第二个上传域是pics,上传多张图片.使用如下代码,总是报错 ...

  5. php四种基础排序算法的运行时间比较

    /** * php四种基础排序算法的运行时间比较 * @authors Jesse (jesse152@163.com) * @date 2016-08-11 07:12:14 */ //冒泡排序法 ...

  6. 伪装隐藏Nginx,PHP版本号提升服务器安全性

    可能有时候我们看某些站点想知道别人在使用什么版本的web服务器之类的信息时,却发现并未显示版本号,甚至连WEB服务器都有变化,可以通过以下 方法来隐藏Nginx.PHP的版本号信息,来提升一定的安全性 ...

  7. Nginx禁止通过IP,未绑定域名访问服务器

    这几天查看CNZZ统计后台看到,我的IP被两个未知的域名绑定了,为了避免被天朝和谐掉, 可以在Nginx上设置禁止通过IP访问服务器,只能通过绑定域名访问(同时设置未绑定域名返回500错误或者跳转到我 ...

  8. poj 3373 Changing Digits (DFS + 记忆化剪枝+鸽巢原理思想)

    http://poj.org/problem?id=3373 Changing Digits Time Limit: 3000MS   Memory Limit: 65536K Total Submi ...

  9. 实时动态更新曲线图,x轴时间s随数据的变化而变化

    $(function () {    $(document).ready(function () {        Highcharts.setOptions({            global: ...

  10. Java 代码优化过程的实例介绍

    衡量程序的标准 衡量一个程序是否优质,可以从多个角度进行分析.其中,最常见的衡量标准是程序的时间复杂度.空间复杂度,以及代码的可读性.可扩展性.针对程序的时间复杂度和空间复杂度,想要优化程序代码,需要 ...