Codeforces Round #553 (Div. 2) 【C. Problem for Nazar】

题目大意:
一开始第一行是 1,第二行是2 4 ,第三行是3 5 7 9 ,类似这样下去,每一行的个数是上一行的个数,然后对这些点从第一个进行编号,问你从[l,r]区间数的和。
思路:分别求出奇数和偶数的个数。然后开始暴力。居然过了==
公式;前m个奇数的和是(m^2),前m个偶数的和是(m*(m+1))。
#include<bits/stdc++.h> using namespace std;
#define int unsigned long long
#define mod 1000000007
int fqow(int a,int b){
int ans=;
while(b){
if(b%){
ans*=a;ans%=mod;
}
b/=;
a*=a;
a%=mod;
}
return ans;
}
int slove(int n){
int sodd=;int seven=;
int sum=;int add=;int cnt=;//次数
for(;;){
if(sum>n){
break;
}
add*=;
cnt++;//次数
if(cnt%){
sodd+=add;
}else{
seven+=add;
}
sum+=add;
}
if(cnt%){
int temp=n-(sum-add);
sodd-=add;
sodd+=temp;
}else{
int temp=n-(sum-add);
seven-=add;
seven+=temp;
} int ans1=(sodd%mod)*((sodd)%mod)%mod;
int ans2=(seven%mod)*((seven+)%mod)%mod;
return (ans1%mod+ans2%mod)%mod; }
signed main(){
int L,R;
cin>>L>>R;
// cout<<slove(L)<<" "<<slove(R)<<" "<<'\n';
cout<<(slove(R)%mod-slove(L-)%mod+mod)%mod<<'\n';
return ;
} /*
1 3 5 7 9 25
1 3 5 7 16
1 3 5 8
1 3 4 2 4 6
odd 1 4 16 64
even 2 8 32
2 4 6 12 2 4 6 8 20
*/
Codeforces Round #553 (Div. 2) 【C. Problem for Nazar】的更多相关文章
- Codeforces Round #343 (Div. 2)【A,B水题】
A. Far Relative's Birthday Cake 题意: 求在同一行.同一列的巧克力对数. 分析: 水题~样例搞明白再下笔! 代码: #include<iostream> u ...
- Codeforces Round #508 (Div. 2)【A,B,C,D】【实验室日常周赛训练】
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f3f3f #define int long long ...
- Codeforces Round #401 (Div. 2)【A,B,C,D】
最近状态极差..水题不想写,难题咬不动..哎,CF的题那么简单,还搞崩了= =.真是巨菜无比. Codeforces777A 题意:略. 思路: 构造出3!次变换,然后输出就好. Code: #inc ...
- Codeforces Round #646 (Div. 2)【B. Subsequence Hate题解】
具体思路已经在代码注释中给出,这里不再赘述. #include<iostream> #include<algorithm> using namespace std; int t ...
- Codeforces Round #367 (Div. 2) C. Hard problem
题目链接:Codeforces Round #367 (Div. 2) C. Hard problem 题意: 给你一些字符串,字符串可以倒置,如果要倒置,就会消耗vi的能量,问你花最少的能量将这些字 ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #443 (Div. 2) 【A、B、C、D】
Codeforces Round #443 (Div. 2) codeforces 879 A. Borya's Diagnosis[水题] #include<cstdio> #inclu ...
- Codeforces Round #436 (Div. 2)【A、B、C、D、E】
Codeforces Round #436 (Div. 2) 敲出一身冷汗...感觉自己宛如智障:( codeforces 864 A. Fair Game[水] 题意:已知n为偶数,有n张卡片,每张 ...
随机推荐
- vim入门一 常用指令
以下为自己常用的vim指令总结 一.插入命令 a 在光标所在字符后进入插入模式 A 调到光标所在行行尾进入插入模式 i 在光标所在字符前插入模式 I 调到光标所在行行首进入插入模式 o 调到光标所在上 ...
- 【动态规划】Concerts
Concerts 题目描述 John enjoys listening to several bands, which we shall denote using A through Z. He wa ...
- c++学习---迭代器
迭代器类型: begin和end的返回值的类型由对象是否为常量所决定 无论对象是都为常量,cbegin和cend都将都到一个const_iterator
- Skip List(跳跃表)原理详解与实现
ref : https://dsqiu.iteye.com/blog/1705530 本文内容框架: §1 Skip List 介绍 §2 Skip List 定义以及构造步骤 §3 Skip ...
- 使用paypal-php-sdk开发php国际支付
参考:https://github.com/paypal/PayPal-PHP-SDK/wiki https://blog.csdn.net/markely/article/details/79044 ...
- 怎样修改原型对象prototype
修改原型对象的方法分为两种情况, 一种是对原型对象的属性方法做增删改, 一种改变原型对象的指向. 第一种: 对原型对象的属性/方法做增删改 function Person(name){ this.na ...
- CentOS下 .Net Core 1.0 升级到 3.0 遇到的一个小问题
之前.net core 1.0的安装方式,不是用yum方式安装的,所以,在用yum安装3.0之后,用dotnet --version还是1.0的版本,想起了之前 做过链接映射dotnet目录,删除之前 ...
- Asp.net core中间件实现原理及用法解说
简述asp.net core中间件的实现思路 原文地址:https://www.cnblogs.com/shengyu-kmust/p/11583974.html 一次http请求的过程,就是对一个R ...
- lambda select和where区别
本文用一个linq to xml语法作为示例,以下是用来操作的xml:<?xml version="1.0" encoding="utf-8" stand ...
- 嵌套的页面——自适应高度与跨越操作DOM
<div id="myIframeId"> <iframe ref="myIframe" name="odpIframeName&q ...