C. Problem for Nazar
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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,…), and the second set consists of even positive numbers (2,4,6,8,…). 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,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 1000000007 (109+7).

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

Input

The first line contains two integers ll and rr (1≤l≤r≤1018) — the range in which you need to find the sum.

Output

Print a single integer — the answer modulo 1000000007 (109+7).

Examples
input
1 3
output
7
input
5 14
output
105
input
88005553535 99999999999
output
761141116
Note

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

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

链接: http://codeforces.com/contest/1151/problem/C

赛后补题。

题意:给你一个无穷的数列 数列的第一部分长度为 1 ,由(1)组成、第二部分长度是2,由 (2 4) 组成、第三部分长度为4 由(3 5 7 9)组成,接下来的还是同样的规律:长度*2 奇偶互换。 求[l,r]这个区间的区间和。

  常规的区间操作 【l,r】 = 【1,r】- 【1,l-1】

  枚举每个子区间,统计出来奇数和偶数的个数,然后就是等差数列求和。

  

#include<cstdio>
#include<algorithm>
using namespace std;
#define ll long long const ll mod = 1e9+;
ll solve(ll x){
ll cnt[] = {,};
int k = ;// 记录奇偶位
ll c = ; // 记录区间的长度
while(x){
cnt[k] += min(c,x);
// 当最后的那个区间长度小于 2^(n-1) (n是区间的个数) 时
// 才会 cnt[k] += x;
x -= min(c,x);
k^=;
c <<= ;
}
ll sum = (cnt[]%mod)*(cnt[]%mod)%mod;
sum += (cnt[]%mod)*((cnt[]+)%mod)%mod;
return sum%mod;
} int main(){
ll l, r;
scanf("%I64d%I64d",&l,&r);
printf("%I64d\n",(solve(r)-solve(l-)+mod)%mod);
return ;
}

Codeforces Round #553 (Div. 2) C的更多相关文章

  1. Codeforces Round #553 (Div. 2) D题

    题目网址:http://codeforces.com/contest/1151/problem/D 题目大意:给出n组数对,(ai , bi),调整这n组数对的位置,最小化 ∑(ai*( i -1)+ ...

  2. Codeforces Round #553 (Div. 2) C题

    题目网址:http://codeforces.com/contest/1151/problem/C 题目大意:给定奇数集和偶数集,现构造一个数组,先取奇数集中一个元素1,再取偶数集二个元素2,4,再取 ...

  3. Codeforces Round #553 (Div. 2) B题

    题目网址:http://codeforces.com/contest/1151/problem/B 题目大意:给定一个n*m的矩阵,问是否可以从每一行中选择一个数,使得这n个数异或大于0,如果可以还要 ...

  4. Codeforces Round #553 (Div. 2) A题

    题目网址:http://codeforces.com/contest/1151/problem/A 题目大意:给定一个由大写字母构成的字符串和它的长度,有这样的操作,使任意一个字母变成与其相邻的字母, ...

  5. Codeforces Round #553 (Div. 2) E 贡献

    https://codeforces.com/contest/1151/problem/E 题意 一条长n的链,每个点上有值\(a[i]\),定义\(f(l,r)\)为该区间的\(值\)所代表的点留下 ...

  6. Codeforces Round #553 (Div. 2) C 等差数列求和 + 前缀和

    https://codeforces.com/contest/1151/problem/C 题意 有两个等差数列(1,3,5,..),(2,4,6,...),两个数列轮流取1,2,4,...,\(2^ ...

  7. Codeforces Round #553 (Div. 2)

    传送门 A. Maxim and Biology 题意: 给出一个串s,问最少需要多少步操作使得串s包含"ACTG"这个子串,输出最少操作次数: 题解: 枚举每个位置 i,求出将 ...

  8. Codeforces Round #553 (Div. 2) C. Problem for Nazar 数学

    题意:从奇数列 1 3 5 7 9 ....  偶数列2 4 6 8 10...分别轮流取 1 2 4 ....2^n 个数构成新数列 求新数列的区间和 (就一次询问) 思路:首先单次区间和就是一个简 ...

  9. Codeforces Round #553 (Div. 2) D. Stas and the Queue at the Buffet 贪心+公式转化

    题意 给出n个pair (a,b) 把它放在线性序列上 1--n 上 使得  sum(a*(j-1)+b*(n-j))  最小 思路 :对式子进行合并 同类项 有:    j*(a-b)+  (-a+ ...

随机推荐

  1. EF中的Guid主键

    除了自增长ID(int),我们还能把主键设置为GUID类型的. 创建我们的数据表 CREATE TABLE dbo.JoinA( AGUID UNIQUEIDENTIFIER PRIMARY KEY ...

  2. Java 深入理解内部类

    摘自海子:Java内部类详解 深入理解内部类 1.为什么成员内部类可以无条件访问外部类的成员? 在此之前,我们已经讨论过了成员内部类可以无条件访问外部类的成员,那具体究竟是如何实现的呢?下面通过反编译 ...

  3. FMDB数据库使用

    创建数据库路径 NSString* docsdir = [NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainM ...

  4. Vue 源码分析—— 目录结构

    一,Vue.js 的源码都是在src 目录下,其目录结构如下. 1.compiler 目录包含Vue.js 所有编译相关的代码.它包括把所有模板解析成ast 语法树, ast 语法树优化等功能. 2. ...

  5. Spring Bean d的作用域

    在spring中,可以在<bean>元素的scop属性里设置bean的作用域,以决定这个bean是单实例的还是多实例的. 默认情况下,spring只为每个在IOC容器里声明的bean创建唯 ...

  6. webstorm累计

    websorm官网下载安装: 1.一下粗略截图说明,点击下一步下一步安装到合适的路径下. 2.next下一步下一步安装成功后弹出,点击ok就行. 2.再次运行webstorm快捷方式打开:界面如下: ...

  7. Spring AOP代理模式

    代理模式 代理模式是一种设计模式,提供了对目标对象的另外的访问方式.即通过代理访问目标对象. 好处:可以再目标对象实现的基础上,增加额外的功能的操作.扩展目标对象的功能,而不改变现有的功能逻辑. 1. ...

  8. php wamp基础环境搭建

    一.apache 安装配置: 1.安装apache 1.1 下载地址:https://www.apachelounge.com/download/ 1.2 将下载的文件解压到你想安装的目录 D:\WA ...

  9. ETL项目1:大数据采集,清洗,处理:使用MapReduce进行离线数据分析完整项目

    ETL项目1:大数据采集,清洗,处理:使用MapReduce进行离线数据分析完整项目 思路分析: 1.1 log日志生成 用curl模拟请求,nginx反向代理80端口来生成日志. #! /bin/b ...

  10. Flume(3)-安装部署

    一. 下载 Flume官网地址 http://flume.apache.org/ 文档查看地址 http://flume.apache.org/FlumeUserGuide.html 下载地址 htt ...