码迷,mamicode.com
首页 > 其他好文 > 详细

(hdu)5391 Zball in Tina Town

时间:2016-08-19 20:32:33      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: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 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≤105,2≤n≤109
 

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

Sample Input
2
3
10
 

Sample Output
2
0

题意:求(n-1)!对n取模

方法:如果是素数就是n-1,如果不是素数(除了4)都是0,4的结果是2 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define N 10010
#define ll long long
#define met(a,b) memset(a,b,sizeof(a));
vector<vector<int> >Q;
int n;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int f=0;
        scanf("%d",&n);

        if(n==4)///特例
        {
            printf("2\n");
            continue;
        }
        int k=(int)sqrt(n);
        for(int i=2; i<=k; i++)
        {
            if(n%i==0)
            {
                f=1;
                break;
            }

        }

        if(f)
            printf("0\n");
        else
            printf("%d\n",n-1);
    }
    return 0;
}

 

(hdu)5391 Zball in Tina Town

标签:

原文地址:http://www.cnblogs.com/jun939026567/p/5788846.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!