//求(n-1)!%n
//n 为合数,答案为0,n为素数 。 威尔逊定理可得
//判定一个自然数是否为素数的充分必要条件。 即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p )
//答案为(n-1) 注意4的时候
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std ;
const int maxn = 1e5 +10 ;
int len ;
int isp[maxn] , a[maxn] ;
void get_prime()
{
memset(isp , 0 , sizeof(isp)) ;
len = 0 ;
for(int i = 2;i < maxn;i++)
{
if(isp[i])continue ;
a[++len] = i ;
for(int j = i ;j < maxn;j+=i)
isp[j] = 1 ;
}
}
int main()
{
int n , t ;
get_prime() ;
scanf("%d" , &t) ;
while(t--)
{
scanf("%d" , &n) ;
if(n == 4)
{
puts("2") ;
continue ;
}
int flag = 0 ;
for(int i = 1;i <= len;i++)
if(a[i]*a[i] > n)break;
else if(n%a[i] == 0)
{
flag = 1;
break;
}
if(flag)puts("0");
else printf("%d\n" , n-1) ;
}
return 0 ;
}

hdu5391Zball in Tina Town的更多相关文章

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

  2. (hdu)5391 Zball in Tina Town

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

  3. hdu5392 Infoplane in Tina Town(LCM)

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

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

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

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

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

  6. hdu 5392 Infoplane in Tina Town(数学)

    Problem Description There is a big stone with smooth surface in Tina Town. When people go towards it ...

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

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

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

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

  9. hdu5391-Zball in Tina Town-威尔逊定理(假证明)

    Tina Town is a friendly place. People there care about each other. Tina has a ball called zball. Zba ...

随机推荐

  1. 前后端分离开发,跨域访问的apche设置

    1,如何让Apache支持跨域访问呢? 步骤: 修改httpd.conf,windows中对应的目录是:C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf 把 ...

  2. iOS 常见小问题

    1. iOS 编译后上下有黑边 ? 缺少启动图片 2.Failed to instantiate the default view controller for UIMainStoryboardFil ...

  3. MVVM 中 ViewModelBase和 CommandBase

    public class ViewModelBase : INotifyPropertyChanged , IDisposable { public virtual string DisplayNam ...

  4. poj1363——Rails

    Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...

  5. GCC 优化选项 -O1 -O2 -O3 -OS 优先级,-FOMIT-FRAME-POINTER(O3的优化很小,只增加了几条优化而已)

    四种编译优化类型的解释: `-O ' `-O1 '                 Optimize.      Optimizing   compilation   takes   somewhat ...

  6. CoreData 从入门到精通(五)CoreData 和 TableView 结合

    我们知道 CoreData 里存储的是具有相同结构的一系列数据的集合,TableView 正好是用列表来展示一系列具有相同结构的数据集合的.所以,要是 CoreData 和 TableView 能结合 ...

  7. ElasticSearch 深入理解 三:集群部署设计

    ElasticSearch 深入理解 三:集群部署设计 ElasticSearch从名字中也可以知道,它的Elastic跟Search是同等重要的,甚至以Elastic为主要导向. Elastic即可 ...

  8. JavaScript学习记录二

    title: JavaScript学习记录二 toc: true date: 2018-09-13 10:14:53 --<JavaScript高级程序设计(第2版)>学习笔记 要多查阅M ...

  9. NPOI简单的给某个单元格字体设置颜色

    参考文档有: https://www.cnblogs.com/gossip/p/4307486.html https://bbs.csdn.net/topics/391042064?page=1 效果 ...

  10. ubuntu上配tensorflow

    前一阵绕了大弯路,基本弄好了UEFI双系统后,面对的就是CUDA咋装在Linux. 好在教程好多,有些朋友建议先装CUDA再装显卡驱动.弄好之后记录一下详细过程吧. *** 这两天看了一些教程,还是感 ...