CF 340A The Wall

原创 2015年07月10日 15:11:42

题目链接:http://codeforces.com/problemset/problem/340/A

A. The Wall

time limit per test:1 second

memory limit per test:256 megabytes

input:standard input

output:standard output

Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.

Iahub has the following scheme of painting: he skips x - 1 consecutive bricks, then he paints the x-th one. That is, he’ll paint bricks x, 2·x, 3·x and so on red. Similarly, Floyd skips y - 1 consecutive bricks, then he paints the y-th one. Hence he’ll paint bricks y, 2·y, 3·y and so on pink.

After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number a and Floyd has a lucky number b. Boys wonder how many bricks numbered no less than a and no greater than b are painted both red and pink. This is exactly your task: compute and print the answer to the question.

Input

The input will have a single line containing four integers in this order: x, y, a, b. (1 ≤ x, y ≤ 1000, 1 ≤ a, b ≤ 2·109, a ≤ b).

Output

Output a single integer — the number of bricks numbered no less than a and no greater than b that are painted both red and pink.

Sample test(s)

Input
2 3 6 18

Output
3

Note

Let’s look at the bricks from a to b (a = 6, b = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.

解题思路:求a到b内既能整除x,又能整除y的所有数的个数(包括a,b)

#include<iostream>
using namespace std;
int f(int a ,int b)
{
    int t ,x =a ,y =b;
    if(x <y) {
        t = x;
        x = y;
        y = t;
    }

    while(x % y!=0)
    {
       t = y;
       y = x % y;
       x = t;   
    }
   return a * b /y; 
}
int main() 
{
    int x ,y ,a ,b;
    while(cin>>x>>y>>a>>b)
    {
        int t= f(x ,y);
        int p;
        p =(a %t==0)? b/t-a/t+1 : b/t-a/t;

        cout <<p <<endl;
    }

    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

cf round340 div2 F(莫队)

题目链接:传送门 E. XOR and Favorite Number time limit per test 4 seconds memo...

Great Wall

  • 2017-07-24 16:00
  • 120KB
  • 下载

UVA 340 Master-Mind Hints

Master-Mind Hints Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & ...

m0n0wall配置手册

  • 2013-08-23 16:13
  • 2.18MB
  • 下载

precast wall

  • 2013-09-05 15:22
  • 253KB
  • 下载

CH340T制作STC51单片机下载器

一直以来在搞 freescale,反倒是51手很生。一直也没有自己做过系统板之类的东西,暑假里准备比赛的这几天,就仔细的翻阅了一下51相关的内容,自己制作了一个小系统版。下载器用的是USB-UART的...

m0n0wall双线教程上

  • 2012-12-29 16:35
  • 1.39MB
  • 下载

Wall Paper 3

  • 2011-10-07 20:04
  • 2.86MB
  • 下载

UVa 340 - Master-Mind Hints

在写这个程序之前,让我们先学习一下英语.╮(╯▽╰)╭ In this problem you will be given a secret code  and a guess  , and are...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)