CF1151C.Problem for Nazar

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task.

Consider two infinite sets of numbers. The first set consists of odd positive numbers (1,3,5,7,…1, 3, 5, 7, \ldots), and the second set consists of even positive numbers (2,4,6,8,…2, 4, 6, 8, \ldots). At the first stage, the teacher writes the first number on the endless blackboard from the first set, in the second stage — the first two numbers from the second set, on the third stage — the next four numbers from the first set, on the fourth — the next eight numbers from the second set and so on. In other words, at each stage, starting from the second, he writes out two times more numbers than at the previous one, and also changes the set from which these numbers are written out to another.

The ten first written numbers: 1,2,4,3,5,7,9,6,8,101, 2, 4, 3, 5, 7, 9, 6, 8, 10. Let's number the numbers written, starting with one.

The task is to find the sum of numbers with numbers from ll to rr for given integers ll and rr. The answer may be big, so you need to find the remainder of the division by 10000000071000000007 (109+710^9+7).

Nazar thought about this problem for a long time, but didn't come up with a solution. Help him solve this problem.

纳扎尔是克雷姆兰王国科学中学的一名学生,以卓越的数学能力而闻名。今天,数学老师给他布置了一道非常困难的题目。

考虑两个无限数集:第一个集合由所有正奇数组成(1,3,5,7,…1, 3, 5, 7, \ldots),第二个集合由所有正偶数组成(2,4,6,8,…2, 4, 6, 8, \ldots)。在第一阶段,老师从第一个集合中写出第一个数;在第二阶段,从第二个集合中写出前两个数;在第三阶段,从第一个集合中写出接下来的四个数;在第四阶段,从第二个集合中写出接下来的八个数;依此类推。换言之,从第二阶段开始,每一阶段所写出的数字个数是前一阶段的两倍,且所取数字的集合在两个集合之间交替切换。

前十个被写出的数为:1,2,4,3,5,7,9,6,8,101, 2, 4, 3, 5, 7, 9, 6, 8, 10。我们对这些写出的数从 11 开始编号。

任务是:对于给定的整数 ll 和 rr,求编号从 ll 到 rr 的所有数的和。答案可能很大,因此你需要输出该和对 10000000071000000007(即 109+710^9+7)取模的结果。

纳扎尔长时间思考了这个问题,但仍未找到解法。请帮助他解决这个问题。

输入格式

The first line contains two integers ll and rr (1≤l≤r≤10181 \leq l \leq r \leq 10^{18}) — the range in which you need to find the sum.

第一行包含两个整数 ll 和 rr(1≤l≤r≤10181 \leq l \leq r \leq 10^{18})——你需要在此范围内求和。

输出格式

Print a single integer — the answer modulo 10000000071000000007 (109+710^9+7).

输出一个整数——答案对 10000000071000000007(即 109+710^9+7)取模的结果。

输入输出样例

  • 输入#1

    1 3

    输出#1

    7
  • 输入#2

    5 14

    输出#2

    105
  • 输入#3

    88005553535 99999999999

    输出#3

    761141116

说明/提示

In the first example, the answer is the sum of the first three numbers written out (1+2+4=71 + 2 + 4 = 7).

In the second example, the numbers with numbers from 55 to 1414: 5,7,9,6,8,10,12,14,16,185, 7, 9, 6, 8, 10, 12, 14, 16, 18. Their sum is 105105.

在第一个例子中,答案是前三个写出的数字之和(1+2+4=71 + 2 + 4 = 7)。

在第二个例子中,从 55 到 1414 对应的数字为:5,7,9,6,8,10,12,14,16,185, 7, 9, 6, 8, 10, 12, 14, 16, 18。它们的和为 105105。

输入解题思路,AI测评打分。不知道怎么写?

首页