(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. JQuery(三) Ajax相关

    JQuery大大简化了Ajax通用操作,开发者只需要指定请求URL,回调函数即可. 三个主要方法: $().param(obj):将obj参数(对象或数组)转化成查询字符串. {name:" ...

  2. 使用weinre通过PC浏览器调试手机网页

    Weinre是什么? Weinre代表Web Inspector Remote,是一种远程调试工具.举个例子,在电脑上可以即时的更改手机上对应网页的页面元素.样式表, 或是查看Javascript变量 ...

  3. Python Socket,How to Create Socket Server? - 网络编程实例

    文章出自:Python socket – network programming tutorial by Silver Moon 原创译文,如有版权问题请联系删除. Network programin ...

  4. java学习--抽象类与接口

    一.抽象 在使用抽象类时需要注意几点: 1.抽象类不能被实例化,实例化的工作应该交由它的子类来完成,它只需要有一个引用即可. 2.抽象方法必须由子类来进行重写. 3.只要包含一个抽象方法的抽象类,该方 ...

  5. SDC(4)–set_clock_groups 与–add选项

    1,set_clock_groups  -exclusive 有多个时钟,但是多个时钟不会同时生效 例如: 2,-add 只有一个时钟输入源,但是始终的频率等可能变 例如:

  6. Javascript 5种方法实现过滤删除前后所有空格

    第一种:循环检查替换 //供使用者调用 function trim(s){ return trimRight(trimLeft(s)); } //去掉左边的空白 function trimLeft(s ...

  7. pptpvpn记录用户登录和流量信息

    这个问题困扰了我很久,终于在pppd的man文档里,发现了踪迹.在man中的SCRIPTS下有一系列的参数,其中PEERNAME就是登陆的用户名,并且在/etc/ppp/ip-up和/etc/ppp/ ...

  8. php PDO连接mysql以及字符乱码处理

    <?php //mysql 的 PDO $dsn = "mysql:dbname=cqkx;host:localhost"; $username = "root&q ...

  9. 九度 链表中倒数第k个结点

    /* * a.cpp * * Created on: 2013-10-7 * Author: wangzhu */ #include<cstdio> #include<iostrea ...

  10. javascript的族家族史

    JavaScript 实现 完整的 JavaScript 实现是由以下 3 个不同部分组成的:ECMAScript.文档对象模型.浏览器对象模型.这也就是说 cocos2d-js 中 其实我们用的是 ...