hdu5391 Zball in Tina Town

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sxy201658506207/article/details/83514393

题意化简后: 给出n 计算(n-1)!%n 输出最小非负整数

            0.若n是素数根据威尔逊定理 答案是 n-1
            1. n不是素数 则 (n-1)! ≡ 0 mod n  (4除外,特判)

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define X 10005
#define inf 0x3f3f3f3f
#define one 0x01
#define PI 3.141592653589793238462643383
const ll N=8*1e7;
int mod=2009;
int a[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        if(n==4) cout<<2<<endl;
        else
        {
            int tag=0;
            for( int i=2; i<=sqrt(n); ++i)
            {
                if(n%i==0)
                {
                    cout<<0<<endl;
                    tag=1;
                    break;
                }
            }
            if(!tag) cout<<n-1<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/sxy201658506207/article/details/83514393
今日推荐