Zball in Tina Town

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1401    Accepted Submission(s): 727

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 $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

题意:求 (n-1)%n,

合数为0,因为1 ~ n-1中必定有积为n(除了4)

质数为n-1,威尔逊定理( p -1 )! ≡ -1 ( mod p )

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
#define N 100005
#define mod 258280327
#define MIN 0
#define MAX 1000001 bool prim(int u)
{
for(int i = 2; i*i <= u; i++)
if(u % i == 0)
return false;
return true;
} int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
if(n == 4)
printf("2\n");
else if(n == 1)
printf("0\n");
else
{
if(prim(n))
printf("%d\n",n-1);
else
printf("%d\n",0);
}
}
return 0;
}

  

hdu 5391 (数论)的更多相关文章

  1. GCD and LCM HDU 4497 数论

    GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...

  2. HDU 5391 水题。

    E - 5 Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  3. HDU 4497 数论+组合数学

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...

  4. hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...

  5. hdu 4961 数论?

    http://acm.hdu.edu.cn/showproblem.php?pid=4961 给定ai数组; 构造bi, k=max(j | 0<j<i,a j%ai=0), bi=ak; ...

  6. hdu 1664(数论+同余搜索+记录路径)

    Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. hdu 3641 数论 二分求符合条件的最小值数学杂题

    http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...

  8. hdu 4059 数论+高次方求和+容斥原理

    http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...

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

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

随机推荐

  1. C程序设计-----第0次作业

    C程序设计-----第0次作业- 1.翻阅邹欣老师的关于师生关系博客,并回答下列问题,每个问题的答案不少于500字:(50分)- 1)最理想的师生关系是健身教练和学员的关系,在这种师生关系中你期望获得 ...

  2. win10 安装mingw ruby rails

    原文可以参考 https://ruby-china.org/topics/17581 在window10 安装ruby rails https://rubyinstaller.org/download ...

  3. Python内置函数(7)——sum

    英文文档: sum(iterable[, start]) Sums start and the items of an iterable from left to right and returns ...

  4. 如何排查CPU飙升的Java问题

    1. JPS 查看jvm进程 2. 显示线程列表 ps -mp pid -o THREAD,tid,time 找到了耗时最高的线程tid 3. tid转换成16进制 printf "%x\n ...

  5. 《深入实践Spring Boot》阅读笔记之三:核心技术源代码分析

    刚关注的朋友,可以回顾前两篇文章: 基础应用开发 分布式应用开发 上篇文章总结了<深入实践Spring Boot>的第二部分,本篇文章总结第三部分,也是最后一部分.这部分主要讲解核心技术的 ...

  6. Window7下安装Jmeter

    解压Jmeter,存放位置为D:\apache-jmeter-2.11 用户变量——>新建变量名JMETER_HOME,变量值为存放目录 系统变量——>添加;%JMETER_HOME%/l ...

  7. spring cloud之坑,访问服务时找不到报404

    主要是因为: 启动时 而我访问时,api是按照下面这样访问的: 所以报404找不到

  8. Mybatis自动生成Xml文件,针对字段类型为text等会默认产生XXXXWithBlobs的方法问题

    默认情况下产生的Mapper.xml里面存在: 需要修改generatorConfiguration.xml,里面的table加属性,如: <table domainObjectName=&qu ...

  9. mybatis的generator中xml配置问题

    <!-- 生成模型的包名和位置 --> <javaModelGenerator targetPackage="com.sung.risk.model.biz" t ...

  10. Mybatis 中的转义字符

    记录以下mybatis中的转义字符,方便以后自己看一下 Mybatis转义字符表 < < 小于 > > 大于 & & 与 &apos; ' 单引号 &q ...