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. Cache Buffer 区别

    Cache 一般位于CPU中, 分为 L1 Cache, L2 Cache, 是一种读的操作,把CPU刚用过的/循环使用的数据存储起来,当CPU再次使用时,可以直接从Cache存储器中调用,减少了等待 ...

  2. java核心技术-多线程之线程内存模型

    对于每一种编程语言,理解它的内存模型是理所当然的重要.下面我们从jvm的内存模型来体会下java(不限java语言,严格来讲是JVM内存模型,所有JVM体系的变成语言均适用)的内存模型. 堆: 就是我 ...

  3. windows10 通过命令行来查看wifi密码

    c:\Windows\System32>netsh netsh>wlan show profile 接口 WLAN 上的配置文件: 组策略配置文件(只读) ---------------- ...

  4. 你不知道的css之 width “继承”篇。

    众所周知,css的三大特性分别是 继承性,层叠性,和优先级. 那么这里就详细说一下css中width的继承性及其特殊情况. 继承性概念详解:css的继承性指的被包在内部的标签拥有外部标签的样式性,子元 ...

  5. 第一章 程序设计和C语言(笔记)

    一.程序和程序语言 程序:完成某项事务所预设的活动方式和活动过程. 程序设计:人们描述计算机要做的工作. 对于工作过程的细节动作描述就是一个“程序”. 在一个程序描述中,总有一批预先假定的“基本动作” ...

  6. Python学习 :常用模块(四)----- 配置文档

    常用模块(四) 八.configparser 模块 官方介绍:A configuration file consists of sections, lead by a "[section]& ...

  7. python学习之简介与环境安装

    [转自]http://www.cnblogs.com/wupeiqi/articles/5433925.html --Python可以应用于众多领域 如:数据分析.组件集成.网络服务.图像处理.数值计 ...

  8. 20155204 2016-2017-2《Java程序设计》课程总结

    20155204 2016-2017-2<Java程序设计>课程总结 目录 作业链接汇总 作业总结 实验报告链接汇总 代码托管链接 课堂项目实践 学习经验 问卷调查 链接二维码 (按顺序) ...

  9. 20155204 实验3《敏捷开发与XP实践》实验报告

    20155204 实验3<敏捷开发与XP实践>实验报告 一.实验内容与步骤 1.研究IDEA的code菜单. 老师给的任务的是把一串代码格式化,这个任务很简单.code菜单主要是关于编辑代 ...

  10. 20155217 2016-2017-2《java程序设计》第一周学习总结

    20155217 2016-2017-2<java程序设计>第一周学习总结 浏览教材,根据自己的理解每章提出一个问题 java平台和java编程语言的区别? 怎样使用IDE来管理原始码与位 ...