标签:
2 3 5 1 10 4 6 9 5 20 4 4 8 10 20
8 7 3
容斥。。。
#include<stdio.h> //#include<bits/stdc++.h> #include<string.h> #include<iostream> #include<math.h> #include<sstream> #include<set> #include<queue> #include<map> #include<vector> #include<algorithm> #include<limits.h> #define inf 0x3fffffff #define INF 0x3f3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define ULL unsigned long long using namespace std; LL x,y,z,a,b; long long gcd(long long a,long long b) { return b?gcd(b,a%b):a; } long long lcm(long long n, long long m) { long long p = gcd(n, m); return (n/p*m); } LL SUM(LL x) { LL sum=0; sum+=(b/x)-(a-1)/x; return sum; } int main () { while(cin>>x>>y>>z>>a>>b) { LL sum_1=0,sum_2=0,sum_3=0; LL sum_4=0; LL sum_5=0; sum_1+=SUM(x); sum_2+=SUM(y); sum_3+=SUM(z); // cout<<lcm(x,y)<<endl; sum_4+=SUM(lcm(x,y))+SUM(lcm(x,z))+SUM(lcm(y,z)); sum_5+=SUM(lcm(lcm(x,y),lcm(y,z))); cout<<sum_1+sum_2+sum_3-sum_4+sum_5<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/yinghualuowu/p/5136597.html