题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391

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 time as large as its original size. On the second day,it will become 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-)-th day. Tina want to know its size on the (n-)-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≤,≤n≤ Output
For each test case, output an integer representing the answer. Sample Input Sample Output

题意:求(n-1)!对n取模

方法:如果是素数就是n-1,如果不是素数(除了4)都是0,4的结果是2

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define N 10010
#define ll long long
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
int n;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int f=;
scanf("%d",&n); if(n==)///特例
{
printf("2\n");
continue;
}
int k=(int)sqrt(n);
for(int i=; i<=k; i++)
{
if(n%i==)
{
f=;
break;
} } if(f)
printf("0\n");
else
printf("%d\n",n-);
}
return ;
}

(hdu)5391 Zball in Tina Town的更多相关文章

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

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

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

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

  3. hdu 5391 Zball in Tina Town 威尔逊定理 数学

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

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

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

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

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

  6. hdoj 5391 Zball in Tina Town

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

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

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

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

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

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

随机推荐

  1. HW5.24

    import java.util.Calendar; public class Solution { public static void main(String[] args) { System.o ...

  2. HDOJ-ACM1013(JAVA)

    这道题也很简单~主要是将输入转为字符串(存储大数,操作字符数组) 题意: 24 : 2 + 4 = 6  输出6 39 : 3 + 9 = 12 , 1 + 2 = 3 输出3 999: 9 + 9 ...

  3. [读书笔记]算法(Sedgewick著)·第一章(2)

    接着上一篇,mindmap更新如下内容. 3.背包.队列和栈 这节主要讲述了这三种数据结构(Bag.Queue.Stack)的API.实现以及链表.Queue和Stack还含有删除元素的方法.并引出了 ...

  4. XXX 用户 is not in the sudoers file. This incident will be reported 的问题解决方案

    说的是,这种问题,是出现在ubuntu系统里. root@SparkSingleNode:/usr/local/jdk# pwd /usr/local/jdk root@SparkSingleNode ...

  5. 关于arm处理器 内存编址模式 与 字节对齐方式 (转)

    转自:http://bavon.bokee.com/5429805.html 在x86+Linux上写的程序,在PC机上运行得很好.可是使用ARM的gcc进行交叉编译,再送到DaVinci目标板上运行 ...

  6. android 处理图片之--bitmap处理

    -2.从资源中获得bitmap Resources res=getResources(); Bitmap bmp=BitmapFactory.decodeResource(res, R.drawabl ...

  7. Eclipse + Pydev 配置Python开发环境

    之前有人问 Eclipse + Pydev 的环境配置问题,在此记录一下. 前提条件:需要安装 Eclipse .jdk.Python.这三个软件都可以在官网上下载. 假设上述软件已经安装好了,下面是 ...

  8. 遇到Class Not registered的COM异常怎么办

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:遇到Class Not registered的COM异常怎么办.

  9. ubuntu14.04 64bit 安装 &amp;&amp; 破解quartus13.0 记录

    安装文件:Quartus-13.0.0.156-linux.iso             Quartus-13.0.0.156-devices-1.iso 1.挂载:sudo mount -o lo ...

  10. Solr学习笔记-在Tomcat上部署执行Solr

    上一篇我们初识了Solr而且学习了Jetty的启动方式.查看了Solr的管理界面,这一篇我们来实如今Tomcat上部署执行Solr. 部署环境: window7 jdk1.6.0_14 Solr-4. ...