hdu5391Zball in Tina Town

//求(n-1)!%n
//n 为合数,答案为0,n为素数 。 威尔逊定理可得
//判定一个自然数是否为素数的充分必要条件。

即:当且仅当p为素数时:( p -1 )! ≡ -1 ( mod p )
//答案为(n-1)  注意4的时候
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std ;
const int maxn = 1e5 +10 ;
int len ;
int isp[maxn] , a[maxn] ;
void get_prime()
{
    memset(isp , 0 , sizeof(isp)) ;
    len = 0 ;
    for(int i = 2;i < maxn;i++)
    {
        if(isp[i])continue ;
        a[++len] = i ;
        for(int j = i ;j < maxn;j+=i)
        isp[j] = 1 ;
    }
}
int main()
{
    int n , t ;
    get_prime() ;
    scanf("%d" , &t) ;
    while(t--)
    {
        scanf("%d" , &n) ;
        if(n == 4)
        {
            puts("2") ;
            continue ;
        }
        int flag = 0 ;
        for(int i = 1;i <= len;i++)
        if(a[i]*a[i] > n)break;
        else if(n%a[i] == 0)
        {
            flag = 1;
            break;
        }
        if(flag)puts("0");
        else printf("%d\n" , n-1) ;
    }
    return 0 ;
}
时间: 2024-11-14 12:46:20

hdu5391Zball in Tina Town的相关文章

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,

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天的时候,

hdu5392 Infoplane in Tina Town(LCM)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Infoplane in Tina Town Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 518    Accepted Submission(s): 74 Problem Description There i

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

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.

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 5392 Infoplane in Tina Town(数学)

Problem Description There is a big stone with smooth surface in Tina Town. When people go towards it, the stone surface will be lighted and show its usage. This stone was a legacy and also the center of Tina Town’s calculation and control system. als

(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