E - Fractions Gym - 102058E (暴力)

About 44 days are left before College Scholastic Ability Test is held. This exam aims to measure students' achievement of National Curriculum standards and scholastic ability required for college education. (http://www.kice.re.kr/sub/info.do?m=0205&s=english)

One of the subjects covered by this test is Mathematics, which consists of 21 multiple choice questions and 9 short-answer questions. The answer of each short-answer question is guaranteed to be a unique positive integer below 1 000, as you can see from the answer sheet below.

However, the organizers might want to give students short-answer questions with non-integer answers, such as 23–√23 or 5353. Usually, the workaround is to write the answer in a canonical form, and then sum up all the integers inside that form and ask students to write that number instead.

In particular, when the answer is a positive rational number abab, the organizers usually ask students to reduce it and sum up the numerator and the denominator of the reduced fraction. For example, when the answer is 18101810, the student should reduce it to 9595 and write the final answer as 9+5=149+5=14.

However, when the answer is 521500521500, the reduced fraction is also 521500521500, so the student should write the final answer as 521+500=1021521+500=1021. But this shouldn't happen, since all the answers for the short-answer questions are below 1 000. To avoid this situation, the organizers should make sure that after reducing the fraction, the sum of the numerator and the denominator shouldn't exceed 999999. Let's call such fractions as Suneung Fractions. For example, 1996219962 and 18101810 are Suneung fractions, while 1998219982 and 521500521500 are not.

Suppose that, this year, one of the organizers wrote a problem, and the answer to that problem is xyxy. Since the problem is not finalized yet, the only thing we know is A≤x≤BA≤x≤B and C≤y≤DC≤y≤D holds, for given A,B,C,DA,B,C,D. The organizers want to know, among all the pairs (x,y)(x,y), how many of xyxy is a Suneung fraction. Write a program that counts this number.

Input

The first and only line contains four space-separated integers A,B,CA,B,C and DD (1≤A≤B≤10121≤A≤B≤1012, 1≤C≤D≤10121≤C≤D≤1012)

Output

Print the number of integral pairs (x,y)(x,y) (A≤x≤BA≤x≤B, C≤y≤DC≤y≤D), where xyxy is a Suneung fraction.

Examples

Input

5 8 3 6

Output

16

Input

2018 2019 2018 2019

Output

2

//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/
//https://www.cnblogs.com/zzrturist/    //博客园
//https://blog.csdn.net/qq_44134712     //csdn

using namespace std;

typedef long long ll;
const ll maxn=1e7+10;

int main(){
    ll a,b,c,d,ans=0;
    cin >> a >> b >> c >> d;
    for(ll i=1;i<=999;i++){
        for(ll j=1;j<=999;j++){
            if(i+j<=999&&__gcd(i,j)==1){
                ll a1=a/i;
                ll a2=b/i;
                ll b1=c/j;
                ll b2=d/j;
                if(a%i==0){
                    a1--;
                }
                if(c%j==0){
                    b1--;
                }
                if(min(a2,b2)-max(a1,b1)>0){
                    ans+=(min(a2,b2)-max(a1,b1));
                }
            }
        }
    }
    cout << ans;
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值