1e9个兵临城下

 

https://ac.nowcoder.com/acm/contest/321#question

代码写得蛮丑的。。真的很丑

像是高中教的veen图,并涉及到容斥原理

 1 #include<cstdio>
 2 #include<cmath>
 3 #include<cstring>
 4 #include<iostream>
 5 #include<algorithm>
 6 #include<bits/stdc++.h>
 7 using namespace std;
 8 #define mem(a) memset(a,0,sizeof(a))
 9 #define ll long long
10 #define maxx 1e9
11 ll gcd(ll a,ll k)
12 {
13     if(k == 0)
14         return a;
15     else
16         return gcd(k,a%k);
17 }
18 
19 int main()
20 {
21     int t;
22     cin>>t;
23     while(t--)
24     {
25         ll a,b,c,u=maxx;
26         cin>>a>>b>>c;
27        ll cnt=1;
28        ll m,n,p;
29        m=a/gcd(a,b)*b;
30        n=a/gcd(a,c)*c;
31        p=b/gcd(b,c)*c;
32        cnt=cnt/gcd(cnt,a)*a;
33        cnt=cnt/gcd(cnt,b)*b;
34        cnt=cnt/gcd(cnt,c)*c;
35        u=u-(u/a+u/b+u/c-u/m-u/n-u/p+u/cnt);
36       cout<<u<<endl;
37     }
38 
39 }
View Code

 

posted @ 2018-12-22 16:23  XXrl  阅读(144)  评论(0编辑  收藏  举报