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 11 time as large as its original size. On the second day,it will become 22 times as large as the size on the first day. On the n-th day,it will become nn 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. 

InputThe first line of input contains an integer TT, representing the number of cases.

The following TT lines, each line contains an integer nn, according to the description. 
T≤105,2≤n≤109T≤105,2≤n≤109 
OutputFor each test case, output an integer representing the answer.Sample Input

2
3
10

Sample Output

2
0 翻译:求(n-1)!%n
前置技能:威尔逊定理
威尔逊定理概念:当且仅当p为素数,(p-1)! ≡ -1 (mod p) → (p-1)!+1 = 0 (mod p)
网上关于定理的证明,什么缩系,死都看不懂,只好记住公式,举举例子说服自己这定理是真的。
1.当p为合数时,(p-1)! %p = 0。假设p=a*b,(p-1)! = 1*2*3*4*...*(p-1),其中有两个数是a和b,则(p-1)!%(a*b)=0;
多出一个1的时候,没办法被p整除。
2.当p为素数时,假设p=7,(p-1) != 1*2*3*4*5*6,关于大家所说的2到p-2这些数两两配对,2和4配对,8%7=1;3和5配对,
15%7=1;配对后模p结果为1,最后一个数模p结果为p-1由同余定理可知再补一个1就可以被p整除
再举例p=11,(p-1)! = 1*2*3*4*5*6*7*8*9*10,两两配对,2*6%11=1; 3*4%11=1; 5*9%11=1; 7*8%11=1; 1*10%11=10;
显然10!再加1就可以被11整除。
3.特例:p=4时,3! = 1*2*3 = 6; 6%4=2, 虽然p是合数,但(p-1)%p !=0
 #include <iostream>
#include<stdio.h>
#include <algorithm>
#include<string.h>
#include<cstring>
#include<math.h>
#define inf 0x3f3f3f3f
#define ll long long
using namespace std; bool flag(int x)
{
int q=sqrt(x);
for(int i=;i<=q;i++)
{
if(x%i==)
return false;
}
return true;
} int main()///hdu5391,威尔逊定理
{
int t;
int n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n==)
printf("2\n");
else if(flag(n))
printf("%d\n",n-);
else printf("0\n");
}
return ;
}
 

hdu5391-Zball in Tina Town-威尔逊定理(假证明)的更多相关文章

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

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

  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

    (n-1)!/n 就是如果n为素数,就等于n-1else为0. 求素数表: Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memo ...

  4. hdu5391 Zball in Tina Town

    Problem Description Tina Town is a friendly place. People there care about each other. Tina has a ba ...

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

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

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

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

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

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

  8. BC - Zball in Tina Town (质数 + 找规律)

    Zball in Tina Town  Accepts: 541  Submissions: 2463  Time Limit: 3000/1500 MS (Java/Others)  Memory ...

  9. Zball in Tina Town

    Zball in Tina Town  Accepts: 356  Submissions: 2463  Time Limit: 3000/1500 MS (Java/Others)  Memory ...

  10. 【HDU5391】Zball in Tina Town

    [题目大意] 一个球初始体积为1,一天天变大,第一天变大1倍,第二天变大2倍,第n天变大n倍.问当第 n-1天的时候,体积变为多少.注意答案对n取模. [题解] 根据威尔逊定理:(n-1)! mod ...

随机推荐

  1. 【LeetCode】4. 寻找两个有序数组的中位数

    给定两个大小为 m 和 n 的有序数组 nums1 和 nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n)). 你可以假设 nums1 和 nums2  ...

  2. Windows Server 2012R2 网络地址转换NAT

    一.NAT概述 网络地址转换NAT(Network Address Translation)可以动态改变通过路由器的IP报文的内容(修改报文的源IP地址和/或目的IP地址).离开路由器的报文的源地址或 ...

  3. 基于Linux命令行KVM虚拟机的安装配置与基本使用

    背景 由于生产环境的服务器并不会安装桌面环境,简单操作的图形化安装也不适合批量部署安装.因此,我还是更倾向于在命令下安装配置KVM虚拟机.结合了一些资料和个人使用的状况,我大致列出了一些基本和常用的使 ...

  4. WPF圆角按钮与触发颜色变化

    <Button x:Name="button1" Content="按钮1" Margin="10,10,0,0" Cursor=&q ...

  5. Ajax总结一下

    一.什么是Ajax Ajax(Asynchronous JavaScript and XML),可以理解为JavaScript执行异步网络请求.通俗的理解的话就是,如果没有Ajax技术,改变网页的一小 ...

  6. jQuery对象的属性操作

    jquery的属性操作模块分为四个部分:html属性操作,dom属性操作,类样式操作和值操作 html属性操作:是对html文档中的属性进行读取,设置和移除操作.比如attr().removeAttr ...

  7. HPROF - Heap Profile

    基于动态链接库实现,可用于性能分析,锁内容.诊断memory leak问题等.获得堆开辟信息 java -agentlib:hprof=heap=sites ToBeProfiledClass 帮助文 ...

  8. <转载> maven 详解 http://www.cnblogs.com/binyue/p/4729134.html

    --声明规范 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3 ...

  9. winform/timer控件/权限设置/三级联动

    一.timer控件 组件--timer timer是一个线程,默认可以跨线程访问对象 属性:Enabled--可用性 Interval--间隔时间 Tick:间隔时间发生事件 二.三级联动 例: pu ...

  10. ubuntu14.04 rabbitmq安装与使用 --修改RabbitMQ数据存储位置

    参考:https://blog.csdn.net/tianjiewang/article/details/58383062 说明: ubuntu14.04   rabiitmq 默认 安装路径 /va ...