<题目链接>

Zball in Tina Town

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 2times 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 mod 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
 
解题分析:
此题一看到 (n-1)! 就要立刻想到威尔逊定理,当n为素数时,毫无疑问 (n-1)! %n=n-1 ,但是如果n不是素数,而是合数,应该怎么办呢?我们可以简单的试几个数,如果n为合数,我们发现
(n-1)!中总能够找出一些因子,使它们想乘为n,但是要注意4是个例外,由于4比较靠前,所以(4-1)!不一定能够凑出4,除了这种情况,其他的合数毫无疑问答案都为0。
 
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; int juge(int x)
{
for(int i=;i*i<=x;i++)
{
if(x%i==)return false;
}
return true;
} int main()
{ int t;cin>>t;
while(t--)
{
int n;
scanf("%d",&n);
if(n==)
{
printf("2\n");
}
else
{
if(juge(n))
{
printf("%d\n",n-);
}
else
printf("0\n");
}
}
return ;
}
 
 
2018-07-31

HDU 5391 Zball in Tina Town【威尔逊定理】的更多相关文章

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

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

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

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

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

随机推荐

  1. Ubuntu16.04安装搜狗拼音输入法(中文输入法)

    虽然网上有很多教程,但是我觉得我的很适合那些真正的小白... 1.下载文件 由于我要给多台电脑安装搜狗输入法,所以用的是文件夹安装,不是命令行安装. 打开官网http://pinyin.sogou.c ...

  2. MyBatis学习-入门

    eclipse + jdk 1.8 + mybatis 1.数据库准备 安装mysql数据库,建立数据库test,在test库下建立测试的表 CREATE TABLE `t_user` ( `id` ...

  3. SpringBoot几个重要的事件回调、监听机制

    (1).需要配置在META-INF/Spring.factories 1.ApplicationContextInitializer // // Source code recreated from ...

  4. 经典]Linux内核中ioremap映射的透彻理解【转】

    转自:http://blog.csdn.net/lanyang123456/article/details/7403514 几乎每一种外设都是通过读写设备上的寄存器来进行的,通常包括控制寄存器.状态寄 ...

  5. Windows CreateFont:创建自己的字体

    原文地址:http://blog.csdn.net/softn/article/details/51718347 前面无论是使用文本输出函数还是 static 控件,字体都是默认的,比较丑陋,我们完全 ...

  6. window系统下远程部署Tomcat

    远程访问windows系统,在windows系统上启动tomcat,发布项目.1.拨VPN2.远程桌面连接,cmd --> mstsc 回车,弹出远程桌面连接窗口 3.输入计算机IP:132.2 ...

  7. 【bzoj1901】dynamic ranking(带修改主席树/树套树)

    题面地址(权限题) 不用权限题的地址 首先说说怎么搞带修改主席树? 回忆一般的kth问题,我们的主席树求的是前缀和,这样我们在目标区间的左右端点的主席树差分下就能求出kth. 那么我们如何支持修改操作 ...

  8. dns轮询

    负载均衡最开始一步,利用它实现负载均衡集群的定位

  9. lamp环境搭建之配置apache与fpm方式的php

    配置apache-2.4.9与fpm方式的php-5.4.26 一.apache.MySQL的安装参考<编译安装lamp环境> http://blog.csdn.net/reblue520 ...

  10. CentOS----kdump failed

    启动提示:Starting kdump [failed] kdump 是一种先进的基于 kexec 的内核崩溃转储机制.当系统崩溃时,kdump 使用 kexec 启动到第二个内核.第二个内核通常叫做 ...