E - 5

Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

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

Output

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

Sample Input

2
3
10

Sample Output

2
0

思路:用 long long 直接暴力打个表可以看到21以内的结果, 5以前的没什么规律, 5以后的只要是素数答案是n-1, 不是素数答案都是0。n的取值范围十的九次方, 一般这种题都是水题。

代码:

#include<stdio.h>
#include<string.h>
#include<math.h>

#define N 110

void judge(int n)//判断是否是素数。
{
int i, k, f = 0;
k = (int)sqrt(n);

for(i = 2; i <= k; i++)
{
if(n % i == 0)
{
printf("%d\n", 0);
f = 1;
break;
}
}
if(f ==0)
printf("%d\n", n-1);

}

int main()
{
int t, n;

scanf("%d", &t);

while(t--)
{
scanf("%d", &n);

if(n == 2)
printf("1\n");
else if(n == 3 || n == 4)
printf("2\n");
else if( n == 5)
printf("4\n");
else
{
judge(n);
}
}

return 0;
}

最新文章

  1. SAP CRM 显示消息/在消息中进行导航
  2. activiti-5.15备份记录
  3. myeclipse构建webservice项目
  4. SQL语句创建表和数据库
  5. Navicat Premium 11.0.19中文破解版 安装
  6. smartPtr指针的实现
  7. HTML5结构化标签
  8. Hadoop 学习笔记 (十) hadoop2.2.0 生产环境部署 HDFS HA Federation 含Yarn部署
  9. uva 10911 - Forming Quiz Teams(记忆化搜索)
  10. 通信基站(dfs回溯,思维)
  11. opencv之haar特征+AdaBoos分类器算法流程(二)
  12. Nginx优化use参数epoll,kqueue,rtsig,eventport,poll
  13. 移动端布局方案汇总&amp;&amp;原理解析
  14. North American Invitational Programming Contest 2018
  15. netty例子
  16. shell的while和until 的用法
  17. OC图片滑动验证
  18. JavaScript学习笔记:基础知识点总结
  19. JPA数据懒加载LAZY和实时加载EAGER(转)
  20. linux octave 4.0安装

热门文章

  1. 【X86】---X86处理器大小端的数据存储验证
  2. String.valueOf(null)
  3. MySql笔记(二)
  4. Jenkins介绍与安装
  5. SSAS Tabular表格模型实现动态权限管理
  6. 《ASP.NET Core 高性能系列》关于性能的闲聊
  7. BZOJ 2648 世界树
  8. PBR原理
  9. jenkins 与 gitlab 的持续集成
  10. ubuntu以root身份登录