Zball in Tina Town
Zball in Tina Town
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.
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≤105,2≤n≤109
For each test case, output an integer representing the answer.
- 2
- 3
- 10
- 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的更多相关文章
- 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 ...
- hdu5391 Zball in Tina Town(威尔逊定理)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...
- C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...
- HDU 5391 Zball in Tina Town【威尔逊定理】
<题目链接> Zball in Tina Town Problem Description Tina Town is a friendly place. People there care ...
- hdu 5391 Zball in Tina Town 威尔逊定理 数学
Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Oth ...
- 判素数+找规律 BestCoder Round #51 (div.2) 1001 Zball in Tina Town
题目传送门 /* 题意: 求(n-1)! mod n 数论:没啥意思,打个表能发现规律,但坑点是4时要特判! */ /***************************************** ...
- BC - Zball in Tina Town (质数 + 找规律)
Zball in Tina Town Accepts: 541 Submissions: 2463 Time Limit: 3000/1500 MS (Java/Others) Memory ...
- (hdu)5391 Zball in Tina Town
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendl ...
- hdu 5391 Zball in Tina Town(打表找规律)
问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...
随机推荐
- 用Python处理字幕文件
始 下了部老电影,找到了相关的中英文字幕,奇怪的是,英文字幕能正常现实,中文字幕却不可以,我一度以为是Linux下播放器编码的问题,但是怎么更改设置都无效,而我以前在看其他电影时,中文字幕是正常的.所 ...
- 【BASIS系列】SAP 批量锁住用户和TCODE的方法
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP 批量锁住用户和TCOD ...
- Mac013--Docker安装
一.Docker安装教程 参考:http://www.runoob.com/docker/macos-docker-install.html 可应用brew命令安装,也可自定义下载安装. 应用brew ...
- 触摸板PCB制作-TM12
1.布局: 使 PSoC 与Sensor之间的距离保持最小化是一个不错的做法. 通常将 PSoC 与其他组件一起贴装到底层,而将 CapSense Sensor置于顶层上. Sensor和栅格地层位 ...
- Git-第四篇廖雪峰Git教程学习笔记(3)远程仓库,克隆远端库
1.本次连接的是gitHub仓库. 1>创建SSH Key. ssh-keygen -t rsa -C "youremail@example.com" lfy@lfy-PC ...
- Java-集合第六篇操作集合的工具类Collections
1.Java提供了一个操作Set.List.Map等集合的工具类:Collections. 工具类中提供的方法主要针对Set.List.Map的排序.查询.修改等操作,以及将集合对象设置为不可变.对集 ...
- 洛谷 P3182 [HAOI2016]放棋子(高精度,错排问题)
传送门 解题思路 不会错排问题的请移步——错排问题 && 洛谷 P1595 信封问题 这一道题其实就是求对于每一行的每一个棋子都放在没有障碍的地方的方案数. 因为障碍是每行.每列只有一 ...
- AcWing 154. 滑动窗口(模板)
(https://www.acwing.com/problem/content/156/) 给定一个大小为n≤106n≤106的数组. 有一个大小为k的滑动窗口,它从数组的最左边移动到最右边. 您只能 ...
- python内置函数sorted()及sort() 函数用法和区别
python内置函数sorted(),sort()都有排序的意思,但是两者有本质的区别,sort 是应用在 list 上的方法,sorted 可以对所有可迭代的对象进行排序操作,list 的 sort ...
- 前端:HTML5和CSS3新特性一览
转载:https://www.cnblogs.com/star91/p/5659134.html