//求(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. Python-基础-day6

    1.二进制 前言:计算机一共就能做两件事:计算和通信 2.字符编码 生活中的数字要想让计算机理解就必须转换成二进制.十进制到二进制的转换只能解决计算机理解数字的问题,那么文字要怎么让计算机理解呢? 于 ...

  2. [剑指offer] 1. 二维数组中的查找 (数组)

    注意是有序数组!! 思路: 1.利用二维数组由上到下,由左到右递增的规律,选取右上角或者左下角的元素a[m][n]与target进行比较, 当target小于元素a[m][n]时,那么target必定 ...

  3. Nginx Zabbix

    https://www.cnblogs.com/wangxiaoqiangs/archive/2016/04/20/5412111.html

  4. [Gatsby] Install Gatsby and Scaffold a Blog

    In this lesson, you’ll install Gatsby and the plugins that give the default starter the ability to t ...

  5. linux 命令 xxd

    xxd,能够查看linux下文件的二进制表示.man一下xxd.能够得到下面信息 NAME        xxd - make a hexdump or do the reverse. SYNOPSI ...

  6. CF 447B(DZY Loves Strings-贪心)

    B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. ZOJ 3690 Choosing number(dp矩阵优化)

    Choosing number Time Limit: 2 Seconds      Memory Limit: 65536 KB There are n people standing in a r ...

  8. WPF silverlight获取子控件(获取DataTemplate里的子控件)

    public static class VisualTreeExtensions { /// <summary> /// 获取父节点控件 /// </summary> /// ...

  9. MySQL超级简明基本操作攻略,给自己看(一)

    系统:Ubuntu 14.04 LTS 安装: apt-get install mysql //安装数据库 apt-get install mysql-workbench //安装图形界面 使用: 启 ...

  10. su和sudo的区别与使用,su命令,linux命令

    su和sudo的区别与使用 一.   使用 su 命令临时切换用户身份 1. su 的适用条件和威力 su命令就是切换用户 的工具,怎么理解呢?比如我们以普通用户beinan登录的,但要添加用户任务, ...