Problem Link
1 /*
2 author:OVRee
3 Time:2015-3-6 15:40:33
4 题目大意:
5 输入四个数,分别代表 两个人刷的墙的 编号的基数x,y,以及区间a,b;
6 求 第a块砖到第b块砖都被俩人刷过的砖数
7 思路:为了防止超时,先用辗转相除法求出x,y的最大 公约数,进而求得最小公倍数e,
8 输出[a,b]中e的倍数的个数 即可;
9 */
10 #include<iostream>
11 #include<cmath>
12 #include<algorithm>
13 using namespace std;
14 //辗转相除法求最大公约数
15 int gcd(int c,int d)
16 {
17 if(c > d) swap(c,d);
18 if(d%c == 0) return c;
19 else
20 {
21 d = d%c;
22 gcd(c,d);
23 }
24 }
25 int main()
26 {
27 int x,y,a,b,e;
28 cin >> x >> y >> a >> b;
29 //通过求最大公约数求最小公倍数;
30 int gcdd = gcd(x,y);
31 e = x*y/gcdd;
32 if( a%e != 0 )
33 {
34 cout << (b-a-e+a%e-b%e)/e + 1;
35 }
36 else
37 {
38 cout << (b-a-b%e)/e +1;
39 }
40 return 0;
41 }
42 /*
43 ^ ^
44 / / )
45 / | / / ^
46 | z ____< / / >
47 | | / /
48 Y / /
49 | > < | < /
50 ( O ^ O ) | <
51 > ________ N / /
52 / ^ / / \
53 \_/ (_/ | / /
54 /_/ /
55 <___/--<____/___/
56 */