logo AlgoBeat OnlineJudge
登录 注册

#214708. [2018 KAIST RUN Fall] Fractions

内存限制:1024 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

About 44 days are left before 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 , 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 or . 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 , 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 , the student should reduce it to and write the final answer as .

:::align{center} :::

However, when the answer is , the reduced fraction is also , so the student should write the final answer as . 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 . Let's call such fractions as . For example, and are , while and are not.

Suppose that, this year, one of the organizers wrote a problem, and the answer to that problem is . Since the problem is not finalized yet, the only thing we know is and holds, for given . The organizers want to know, among all the pairs , how many of is a . Write a program that counts this number.

输入格式

The first and only line contains four space-separated integers and (, )

输出格式

Print the number of integral pairs (, ), where is a .

样例

样例输入 1

5 8 3 6

样例输出 1

16

样例输入 2

2018 2019 2018 2019

样例输出 2

2