标签:
明显是无良心的数学round= =
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<algorithm> 5 #include<stack> 6 #include<queue> 7 #include<cstring> 8 #define PAU putchar(‘ ‘) 9 #define ENT putchar(‘\n‘) 10 #define Safe 6 11 using namespace std; 12 typedef long long LL; 13 const int maxn=100000+10; 14 LL gcd(LL a, LL b){ 15 return b == 0 ? a : gcd(b, a % b); 16 } 17 LL n, x, mx; 18 LL mul(LL a, LL b, LL p){ 19 LL tmp = (a * b - (LL)((long double)a / p * b + 1e-8) * p); 20 return tmp < 0 ? tmp + p : tmp; 21 } 22 LL pow(LL a, LL b, LL p){ 23 LL ans = 1; a %= p; 24 for(LL i = b; i; i >>= 1, a = mul(a, a, p)) 25 if(i & 1) ans = mul(ans, a, p); 26 return ans; 27 } 28 bool check(LL a, LL n, LL r, LL s){ 29 LL ans = pow(a, r, n), p = ans; 30 for(int i = 1; i <= s; i ++){ 31 ans = mul(ans, ans, n); 32 if(ans == 1 && p != 1 && p != n - 1) return true; 33 p = ans; 34 } 35 if(ans != 1)return true; 36 return false; 37 } 38 bool MR(LL n){ 39 if(n <= 1) return false; 40 if(n == 2) return true; 41 if(n % 2 == 0) return false; 42 LL r = n - 1, s = 0; 43 while(r % 2 == 0) r /= 2, s ++; 44 for(int i = 0; i < Safe; i ++) 45 if(check(rand() % (n - 1) + 1, n, r, s)) return false; 46 return true; 47 } 48 inline LL read(){ 49 LL x=0;bool sig=1;char ch=getchar(); 50 for(;!isdigit(ch);ch=getchar())if(ch==‘-‘)sig=0; 51 for(;isdigit(ch);ch=getchar())x=10*x+ch-‘0‘; 52 return sig?x:-x; 53 } 54 inline void write(LL x){ 55 if(x==0){putchar(‘0‘);return;}if(x<0)putchar(‘-‘),x=-x; 56 int len=0;static LL buf[20];while(x)buf[len++]=x%10,x/=10; 57 for(int i=len-1;i>=0;i--)putchar(buf[i]+‘0‘);return; 58 } 59 int T; 60 int main(){ 61 T=read();LL x; 62 while(T--){ 63 x=read(); 64 if(x==3){write(2);ENT;continue;} 65 if(x==4){write(2);ENT;continue;} 66 if(MR(x))write(x-1),ENT; 67 else write(0),ENT; 68 } 69 // for(LL x=1;x<=100;x++){ 70 // LL fac=1; 71 // for(int i=2;i<x;i++)fac=fac*i%x;write(x);PAU;write(fac);ENT; 72 // } 73 return 0; 74 }
然后这道题全场都被至少扣了一分,不明觉厉= =
显然不可写= =div1都没有人过= =
标签:
原文地址:http://www.cnblogs.com/chxer/p/4735900.html