#P14628. [2018 KAIST RUN Fall] Fractions

    ID: 14495 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>2018最大公约数 gcd高校校赛

[2018 KAIST RUN Fall] Fractions

题目描述

About 44 days are left before College Scholastic Ability Test\textit{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 1000\textit{unique positive integer below 1\,000}, as you can see from the answer sheet below.

:::align{center} :::

However, the organizers might want to give students short-answer questions with non-integer answers, such as 232\sqrt{3} or 53\frac{5}{3}. 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 ab\frac{a}{b}, 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 1810\frac{18}{10}, the student should reduce it to 95\frac{9}{5} and write the final answer as 9+5=149 + 5 = 14.

:::align{center} :::

However, when the answer is 521500\frac{521}{500}, the reduced fraction is also 521500\frac{521}{500}, 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\textit{Suneung Fractions}. For example, 19962\frac{1996}{2} and 1810\frac{18}{10} are Suneung fractions\textit{Suneung fractions}, while 19982\frac{1998}{2} and 521500\frac{521}{500} are not.

Suppose that, this year, one of the organizers wrote a problem, and the answer to that problem is xy\frac{x}{y}. Since the problem is not finalized yet, the only thing we know is AxBA \le x \le B and CyDC \le y \le 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 xy\frac{x}{y} is a Suneung fraction\textit{Suneung fraction}. Write a program that counts this number.

输入格式

The first and only line contains four space-separated integers A,B,CA, B, C and DD (1AB10121 \le A \le B \le 10^{12}, 1CD10121 \le C \le D \le 10^{12})

输出格式

Print the number of integral pairs (x,y)(x, y) (AxBA \le x \le B, CyDC \le y \le D), where xy\frac{x}{y} is a Suneung fraction\textit{Suneung fraction}.

5 8 3 6
16
2018 2019 2018 2019
2