Zball in Tina Town

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

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 2 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-1)-th day. Tina want to know its size on the (n-1)-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≤105,2≤n≤109

 
Output
For each test case, output an integer representing the answer.
 
Sample Input
2
3
10
 
Sample Output
2
0
 
Source
 思路:当数为素数时,威尔逊;
    当数为非素数,4输出2;
          别的输出0;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=1e3+,M=1e6+,inf=1e9+,mod=;
int prime(int n)
{
if(n<=)
return ;
if(n==)
return ;
if(n%==)
return ;
int k, upperBound=n/;
for(k=; k<=upperBound; k+=)
{
upperBound=n/k;
if(n%k==)
return ;
}
return ;
}
int main()
{
int x,y,z,i,t;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&x);
if(x==)
printf("2\n");
else if(prime(x))
printf("%d\n",x-);
else
printf("0\n");
}
return ;
}

hdu 5391 Zball in Tina Town 威尔逊定理 数学的更多相关文章

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

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

  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. Android搜索控件的基本使用方法

    在Android中,搜索是一个非常核心的功能,我们可以通过它搜索到任意我们可以获得的信息.这些信息可以是存储在手机中的联系人.文件等信息,也可以是在网络上的资源. Android为了给用户提供良好的搜 ...

  2. 【Python之路】第十九篇--Python操作MySQL

    本篇对于Python操作MySQL主要使用两种方式: 原生模块 pymsql ORM框架 SQLAchemy pymsql pymsql是Python中操作MySQL的模块,其使用方法和MySQLdb ...

  3. 【Python之路】第十七篇--Ajax全套

    概述 1.传统的Web应用 一个简单操作需要重新加载全局数据 2.AJAX AJAX,Asynchronous JavaScript and XML (异步的JavaScript和XML),一种创建交 ...

  4. to_base64 --- from_base64

    UPDATE traceroleid_copy SET Pwd=to_base64(Pwd) SELECT from_base64(Pwd) FROM traceroleid_copy

  5. Howto: Performance Benchmarks a Webserver

    Howto: Performance Benchmarks a Webserver last updated June 9, 2006 in CategoriesApache, FreeBSD, Ho ...

  6. python基础之类的isinstance与issubclass、反射

    一 isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的对象 class Foo: pass o ...

  7. tornado下模板引擎的使用

    模板引擎 Tornado中的模板语言和django中类似,模板引擎将模板文件载入内存,然后将数据嵌入其中,最终获取到一个完整的字符串,再将字符串返回给请求者. Tornado =的模板支持“控制语句” ...

  8. C语言-随机数

    C语言使用rand()函数产生随机数, 使用rand()函数之前要先使用srand(time(0)), 以当前时间作为种子, 否则产生的随机数将不会变化. #include <stdio.h&g ...

  9. xshell下载安装

    打开网址http://www.netsarang.com/download/software.html 找到最新版的xshell,点击下载 在跳转的页面填写个人信息,许可证类型选择家庭和学校使用,除了 ...

  10. 在Ubuntu上安装Chrome浏览器和ChromeDriver

    启动脚本后报错 selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have w ...