codeforces 340 A. The Wall

水水的一道题,只需要找xy的最小公倍数,然后找a b区间有多少个可以被xy的最小公倍数整除的数,就是答案。

//============================================================================
// Name        : 2013083101.cpp
// Author      : xindoo
// Version     :
// Copyright   : Your copyright notice
// Description : codeforces 340A
//============================================================================

#include <iostream>
#include <stdio.h>

using namespace std;

int gcd (int a, int b) {
	if (a % b == 0)
		return b;
	else
		return gcd(b, a%b);
}

int main() {
	int x, y, a, b;
	while (scanf("%d %d %d %d", &x, &y, &a, &b) != EOF) {
		int t = x*y/gcd(x, y);
		int ans = b/t - a/t;
		if (a%t == 0)
			ans++;
		cout << ans << endl;
	}
	return 0;
}



posted @ 2013-08-31 15:26  xindoo  阅读(158)  评论(0编辑  收藏  举报