Zball in Tina Town

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] = {1, 1};

void prim()
{
    k = 0;
    //memset(num, 0, sizeof(num));

    for(int i = 2; i < N; i++)
    {
        if(!a[i])
            num[k++] = i;
        for(int j = i+i; j < N; j += i)
            a[j] = 1;
    }
}

int isprime(int n)
{
    if(n == 0 || n == 1)
        return 0;

    for(int i = 0; (long long)num[i]*num[i] <= n; i++)
        if(n % num[i] == 0)
            return false;
    return true;
}

int main()
{
    int t, n;

    scanf("%d", &t);
    prim();

    while(t--)
    {
        scanf("%d", &n);
        if(n <= 4)
            printf("2\n");
        else if(isprime(n))
            printf("%d\n", n-1);
        else
            puts("0");
    }
    return 0;
}
时间: 08-15

Zball in Tina Town的相关文章

Zball in Tina Town(判素数)

Zball in Tina Town Accepts: 397 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.

BC - Zball in Tina Town (质数 + 找规律)

Zball in Tina Town Accepts: 541 Submissions: 2463 Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) 问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候,它会变大22倍.在第nn天的时候,

hdu5391 Zball in Tina Town(威尔逊定理)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 219    Accepted Submission(s): 144 Problem Description Tina Town i

hdu 5391 Zball in Tina Town 威尔逊定理 数学

Zball in Tina Town 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 lar

HDU 5391 Zball in Tina Town【威尔逊定理】

<题目链接> Zball in Tina Town 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 siz

hdu 5391 Zball in Tina Town

点击此处即可传送 hdu 5391 唉,我以为带7的基本上都是素数,所以一直拿1007算,结果....唉,一把辛酸泪啊,算了,不说了,上正事: 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,

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

问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候,它会变大22倍.在第nn天的时候,它会变大nn倍. zball原来的体积是11.Tina想知道,zball在第n-1n−1天时的体积对nn取模是多大呢? Tina是一个蠢蠢的女孩子,当然不会算啦,所以她请你帮她算出这个答案呢. 输入描述 第一行一个正整数TT,表示数据组数 接下来TT行,每行一个正整

(hdu)5391 Zball in Tina Town

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 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 t

hdu 5391 Zball in Tina Town (素数的判断)

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 wil