标签:des mat ott more font eps set double clu
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2957 Accepted Submission(s): 946
1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 #include <climits> 7 #include <cmath> 8 #include <vector> 9 #include <queue> 10 #include <stack> 11 #include <set> 12 #include <map> 13 using namespace std; 14 typedef long long LL ; 15 typedef unsigned long long ULL ; 16 const int maxn = 1e5 + 10 ; 17 const int inf = 0x3f3f3f3f ; 18 const int npos = -1 ; 19 const int mod = 1e9 + 7 ; 20 const int mxx = 100 + 5 ; 21 const double eps = 1e-6 ; 22 const double PI = acos(-1.0) ; 23 24 LL gcd(LL x, LL y){ 25 return y?gcd(y,x%y):x; 26 } 27 int T, tot; 28 LL n, m, a, d, k, ans; 29 LL b[maxn], c[maxn], e[maxn]; 30 int main(){ 31 // freopen("in.txt","r",stdin); 32 // freopen("out.txt","w",stdout); 33 while(~scanf("%d",&T)){ 34 for(int kase=1;kase<=T;kase++){ 35 ans=0LL; 36 tot=0; 37 scanf("%lld %lld",&n,&m); 38 for(LL i=1LL;i<=(LL)sqrt(m);i++) 39 if(0==m%i){ 40 c[tot++]=i; 41 if(i!=m%i) 42 c[tot++]=m/i; 43 } 44 sort(c,c+tot); 45 memset(b,0,sizeof(b)); 46 memset(e,0,sizeof(e)); 47 for(int i=1;i<=n;i++){ 48 scanf("%lld",&a); 49 d=gcd(a,m); 50 b[lower_bound(c,c+tot,d)-c]=1; 51 } 52 for(int i=0;i<tot;i++) 53 if(b[i]) 54 for(int j=i+1;j<tot;j++) 55 if(c[j]%c[i]==0 && b[j]==0) 56 b[j]=1; 57 for(int i=0;i<tot;i++) 58 if(b[i]){ 59 LL cnt=b[i]-e[i]; 60 k=(m-1)/c[i]; 61 // k=(m/c[i])-1; 62 ans+=cnt*k*(c[i]+k*c[i])/2; 63 for(int j=i+1;j<tot;j++) 64 if(c[j]%c[i]==0) 65 e[j]+=cnt; 66 } 67 printf("Case #%d: %lld\n",kase,ans); 68 } 69 } 70 return 0; 71 }
标签:des mat ott more font eps set double clu
原文地址:http://www.cnblogs.com/edward108/p/7642574.html