HDU 5391 (素数+)

    xiaoxiao2026-09-26  11

    Zball in Tina Town

    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 1777    Accepted Submission(s): 902 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   Source BestCoder Round #51 (div.2)   Recommend hujie   |   We have carefully selected several similar problems for you:  5856 5855 5854 5853 5852  题意: 本题就是要求(n-1)的阶乘能否整除n; 分析:1:如果n是合数(不是素数也不是1的自然数) 2:n是素数时,结果为(n-1);  (威尔逊定理    点击打开链接了解威尔逊定理) 注意的是:4 要特殊处理!!! #include<iostream> #include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<stdlib.h> #include<queue> typedef long long ll; using namespace std; #define INF 0x3f3f3f3f int Isprime(int n) ///判断素数 { int k,i; if(n==1) return 0; k=(int)sqrt(n); for(i=2;i<=k;i++) { if(n%i==0) return 0; } return 1; } int main() { int T,n,ans; scanf("%d",&T); while(T--) { scanf("%d",&n); if(n==4) ans=2; else if(!Isprime(n)) ans=0; else ans=n-1; printf("%d\n",ans); } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1312352.html
    最新回复(0)