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. docker搭建harbor私有镜像库

    创建harbor私有镜像库 一.部署准备: harbor软件包   在部署节点上: 1)解压harbor的软件包将harbor目录下所有文件发送到/opt/目录下   tar zxvf harbor- ...

  2. django中orm多表查询,减少数据库查询操作

    .select_related()   的使用

  3. python批量下载验证码,用来做验证码处理

    刚学到爬虫识别验证码,所以自己建一个获取验证码的类,感兴趣的道友,可以看看,代码如下: import requests import time import os import re class Pi ...

  4. Web高级 JavaScript中的算法

    算法 排序算法 稳定排序 待排序序列中相等元素在排序完成后,原有先后顺序不变. 非稳定排序 有序度 待排序序列中有序关系的元素对个数. 逆序度 1. 插入排序 遍历有序数组,对比待插入的元素大小,找到 ...

  5. vue—两个数组,去重相同项

  6. winCE/Windows 应用程序消息提示框自动消失功能

    近期在做winCE系统的扫描枪应用程序,遇到了一些问题,其中包括消失提示框在手持终端显示过小, 用户要求提示框提示几秒后自动关闭,Windows平台可以通过调用系统API以定时器的方式进行自动销毁. ...

  7. java_第一年_JDBC(5)

    事务概念:事务指逻辑上的一组操作,组成这组操作的各个单元,要不全部成功,要不全部不成功: 开始事务:start transaction 提交事务:commit 回滚事务:rollback 事务的四大特 ...

  8. Forbidden (CSRF token missing or incorrect.):错误解决办法

    在JS中,使用post方法提交数据到后台,出现错误: Forbidden (CSRF token missing or incorrect.):.........; 解决办法: 在页面导入JS的位置, ...

  9. HDU-1181 变形课(多种方式,好题)

      首先想到的是并查集,然后WA...原因在这,我第一次敲的是Find(1) == Find(12)来作为可以成功的条件,实际上这样是不行的,比方说 bell 和 mail实际上是不满足条件的,可以理 ...

  10. ofbiz框架以及核心原理介绍

    1. 什么是Ofbiz Ofbiz(Open for business)是一个开源的,基于J2EE和XML规范的,用于构建大型企业级.跨平台.跨数据库.跨应用服务器的多层.分布式电子商务类WEB应用系 ...