QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#13923. 数学问题

الإحصائيات

小时候,小H是一名热爱学习的小学生。有一天,在数学课上,老师留了一道题让大家思考:一个整数,已知它和整数 $a$ 的最大公约数等于 $b$,和整数 $c$ 的最大公约数等于 $d$。请算出这个整数的值。

爱学习的小 H 没花多少时间就发现,可能有很多整数都满足这样的条件,于是就去把疑惑告诉老师。老师很高兴,鼓励小 H 找出不小于整数 $l$ 且不大于整数 $r$ 的所有满足条件的整数有哪些,观察一下有没有什么规律。然而这个问题太困难了,小 H 当时没有解决。

现在,已经读大学的小 H 在翻阅小学日记时重新看到了这个问题,可是依然不会做。请你帮忙解决这个问题。由于满足条件的整数可能有很多,你只需要输出它们的和

输入格式

第一行,一个整数 $T$, 表示有几组测试数据。

接下来 $T$ 行, 每行为六个由空格隔开的正整数, 依次是 $l$, $r$, $a$, $b$, $c$, $d$。

输出格式

输出 $T$ 行,每行一个整数, 依次是每组数据的答案, 即 $l$ 到 $r$ 之间所有和 $a$ 的最大公约数为 $b$ 并且和 $c$ 的最大公约数为 $d$ 的整数之和。 如果不存在这样的整数,输出 0 即可。

样例数据

样例输入

3
1 20 2 2 12 6
4 6 3 3 4 4
1 1000000000 1 1 3 1

样例输出

24
0
333333333666666667

样例解释

第 1 组数据: 1 到 20 之间满足条件的数只有 6 和 18, 和等于 24。

第 2 组数据: 4 到 6 之间不存在满足条件的数。

子任务

对于 $10\%$ 的数据,$1 \le l \le r \le 10^6$

对于 $100\%$ 的数据,$1 \le l \le r \le 10^{30}$, $1 \le a, b, c, d \le 10^{14}$, $1 \le T \le 4$, 保证 $b$ 是 $a$的约数, $d$ 是 $c$ 的约数

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.