Zball in Tina Town

 Accepts: 356
 Submissions: 2463
 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 11 time as large as its original size. On the second day,it will become 22times 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.

Input

The 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 \leq {10}^{5},2 \leq n \leq {10}^{9}T≤10​5​​,2≤n≤10​9​​

Output

For each test case, output an integer representing the answer.

Sample Input
2
3
10
Sample Output
2
0

题意:一个球的原始体积是1,到第n天增大到它的n-1的n倍,体积就是阶乘的意思,结果让我们求n-1天的体积对n的余数,10的9次方,那么大。是,有规律

如果n是素数那么余数就是n-1,如果不是素数对n的余数肯定是0,当然4除外,是2.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm> using namespace std; #define N 100000
#define INF 0xfffffff int num[N], k;
int a[N] = {, }; void prim()
{
k = ;
//memset(num, 0, sizeof(num)); for(int i = ; i < N; i++)
{
if(!a[i])
num[k++] = i;
for(int j = i+i; j < N; j += i)
a[j] = ;
}
} int isprime(int n)
{
if(n == || n == )
return ; for(int i = ; (long long)num[i]*num[i] <= n; i++)
if(n % num[i] == )
return false;
return true;
} int main()
{
int t, n; scanf("%d", &t);
prim(); while(t--)
{
scanf("%d", &n);
if(n <= )
printf("2\n");
else if(isprime(n))
printf("%d\n", n-);
else
puts("");
}
return ;
}

Zball 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. hdu5391 Zball in Tina Town(威尔逊定理)

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

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

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

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

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

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

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

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

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

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

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

  8. (hdu)5391 Zball in Tina Town

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

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

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

随机推荐

  1. hive重要命令

    hadoop dfsadmin -safemode leave hadoop退出安全模式让提示符显示当前库: set hive.cli.print.current.db=true;显示查询结果时显示字 ...

  2. Ansible安装配置(CentOS 7)

    Ansible 中的概念 任务 Task——多个 Task 顺序执行,在每个 Task 执行结束可以通知 Hanlder 触发新操作. 变量 Variable——用户定义的变量. 环境 Facts—— ...

  3. [Git] 010 对 [Git 008] 的补充:实现 commit 不计次数

    回顾:[Git] 008 status 与 commit 命令的补充 的 "2.4" [Git 008] 的 "2.4" 使用 git commit --ame ...

  4. sublime text3插件安装及使用

    sublime官网下载地址:http://www.sublimetext.com/ 我用的是SubLime text3,插件安装命令地址:https://packagecontrol.io/insta ...

  5. 【题解】1-2-K Game

    题目大意   现有\(n\)个东西,每次可以取\(1\)个,\(2\)个或\(k\)个.Alice和Bob轮流取,且Alice先取.问谁是最后一个取的.(\(0 \leq n \leq 10^9\), ...

  6. 埃及分数问题(带乐观估计函数的迭代加深搜索算法-IDA*)

    #10022. 「一本通 1.3 练习 1」埃及分数 [题目描述] 在古埃及,人们使用单位分数的和(形如 $\dfrac{1}{a}​$​​ 的,$a$ 是自然数)表示一切有理数.如:$\dfrac{ ...

  7. SCUT - 106 - 花式ac - 主席树/启发式合并Treap

    https://scut.online/p/106 错在这组样例,发现是离散化之后,对k访问的时候也是应该访问离散化之后的k. 12 4 1 1 2 2 5 5 4 4 3 3 2 1 1 3 3 5 ...

  8. CSS3实现小于1px的边框(移动端)

    <!doctype html> <html lang="en"> <head> <meta content="width=dev ...

  9. html表格单元格添加斜下框线的方法

    一.分隔单元格的方法 1.用“transform: rotate(-55deg);”把一条水平线旋转一定角度就成斜线了 2.利用以下命令调整分割线位置等. :after :before transfo ...

  10. V8引擎回收机制、 内存泄露

     一.垃圾回收:将内存不在使用的数据进行清理,释放内存空间   v8将内存分为新生代空间和老生代的空间   新生代空间:用于存活较短的对象   :又分为二个空间:from空间和to空间   :Scav ...