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. C#之委托(二)

    其实在上一篇委托(一)中,创建委托还是太繁琐了点.代码量过多,可能会妨碍我们对代码和逻辑的理解.有些时候可能处理逻辑的代码都笔声明委托的代码要少,这就不可避免的增加了重复代码的量.所以在c#2中极大的 ...

  2. 16/7/8_PHP-对象的高级特性

    对这个理解不太懂或者说 没有一个明确的用法,不知道该怎么使用,说到底还是不懂有什么用.我还是先把只是点复制过来 对象比较,当同一个类的两个实例的所有属性都相等时,可以使用比较运算符==进行判断,当需要 ...

  3. SSM Maven MallDemo项目为例

    一.创建maven项目 项目结构 创建一个空项目 1. mall (**pom**) 父模块,用于放置公共属性.依赖关系等. 2. mall-util (**jar**) 工具模块,用于放置常用工具类 ...

  4. Centos7上安装Nginx两种方法

    源码编译安装 http://nginx.org/en/download.html 到官网下载,然后用XFTP上传到root目录 把文件解压出来 tar -zxvf nginx-1.16.0.tar.g ...

  5. unity编辑器Hierarchy添加图标

    效果 素材 using UnityEditor; using UnityEngine; using System.Collections.Generic; [InitializeOnLoad] cla ...

  6. MYSQL5.5 linux 多实例

    安装过程 cmake 安装参照上一篇 https://www.cnblogs.com/lixuchun/p/9240888.html 多实例采用 /data 目录作为mysql多实例的总的根目录,然后 ...

  7. TensorFlow学习笔记11-开始用TensorFlow

    TensorFlow运作方式 要用到的代码都在Github上.当然,如果你本地装了TensorFlow,也可以用Everything直接搜索以下文件: mnist.py fully_connected ...

  8. 001/Docker入门(Mooc)

    docker官网:https://www.docker.com/ 1.什么是docker 2.Docker思想     ==> [1].集装箱:保证程序完整(不缺东西,如配置文件等). [2]. ...

  9. 手把手教你用Pytorch-Transformers——实战(二)

    本文是<手把手教你用Pytorch-Transformers>的第二篇,主要讲实战 手把手教你用Pytorch-Transformers——部分源码解读及相关说明(一) 使用 PyTorc ...

  10. [Python3 填坑] 012 字典的遍历在 Python2 与 Python3 中区别

    目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 Python2 中字典的遍历 2.2 Python3 中字典的遍历 2.3 结论 1. print( 坑的信息 ) 挖坑时间:2019/ ...