The number of problem asked by the master description today the Varsity team are ready to relax, our team is ready to choose some numbers to play, but everyone likes the number is different, the disc like X (1<=x<=1^9), Kaikai like Y (1<=y<=1^9) , and I like Z (1<=z<=1^9), the argument is not the result of the case, we decided that as long as it is a multiple of the three number of any number we take, in order to meet the game requirements, we also decided as long as [A, b] in the range of the number (1<=a<=b<=1^ 18), what is the total number of satisfied requirements?
Note: Find the maximum common factor function for A and B:
Long Long gcd (long long A,long long b) {
Return B?GCD (b,a%b): A;
}input multiple sets of data (<=1000), read to the end of the file.
Each group of data is a row of 5 integers, x,y,z,a,b, meaning and data range as described in the topic.
Note Use long longoutput to output an integer for each set of data that represents the number of requests that meet the requirement, with each result occupying one row. Sample Input
2 3 5 1 104 6 9 5 204 4 8 10 20
Sample Output
873
Author Shang
To be tolerant of ...
#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 longusing 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 (x, y), LCM (y,z))); cout<<sum_1+sum_2+sum_3-sum_4+sum_5<<endl; } return 0;}
2015 Suzhou University ACM-ICPC Training Team Tryouts (2) 1004