codeforces 340 A. The Wall

来源:互联网 发布:java math.random 编辑:程序博客网 时间:2024/05/19 15:18

水水的一道题,只需要找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;elsereturn 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;}



原创粉丝点击