HDU 5391 水题。

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;
}

上一篇:通过yocto给p1010rdb定制linux,并启动linux


下一篇:(转)windows上virtualenv 安装及使用