hdu5391 Zball in Tina Town
生活随笔
收集整理的這篇文章主要介紹了
hdu5391 Zball in Tina Town
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意化簡后: 給出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; }?
總結
以上是生活随笔為你收集整理的hdu5391 Zball in Tina Town的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdu4740 Sum
- 下一篇: hdu2973 YAPTCHA