CF 476 div2 C
http://www.codeforces.com/contest/476/problem/C
C. Dreamoon and Sums
1.5 seconds
256 megabytes
standard input
standard output
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if and
, where k is some integer number in range[1, a].
By we denote the quotient of integer division of x and y. By
we denote the remainder of integer division of x andy. You can read more about these operations here: http://goo.gl/AcsXhT.
The answer may be large, so please print its remainder modulo 1 000 000 007 (109 + 7). Can you compute it faster than Dreamoon?
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
1 1
0
2 2
8
For the first sample, there are no nice integers because is always zero.
For the second sample, the set of nice integers is {3, 5}.
题目大意:给你一个公式,输入a和b,对于某满足(x / b) / (x % b) = k(1 <= k <= a),问满足条件的x的总合
思路:我们得到x/b = k * (x%b),令x%b=i,然后枚举i即可得到相应的x = i * k * b + i,
然后即可得到暴力枚举的公式ans = ((1LL * i * ta % mod * b % mod + a * i % mod) % mod + ans) % mod,因此这种方法是O(b)的复杂度( 无语了,这里因为中间的mod爆了LL导致后来卡了一会儿,果然做事需要谨慎点。)
当然如果把i提取出来还可以用O(1)的方法计算。
//看看会不会爆int!数组会不会少了一维!
//取物问题一定要小心先手胜利的条件
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
const int maxn = + ;
const LL mod = 1e9 + ;
LL a, b; int main(){
cin >> a >> b;
LL ans = ;
LL ta = (a + ) * a / % mod;
for (int i = ; i < b; i++){
ans = ((1LL * i * ta % mod * b % mod + a * i % mod) % mod + ans) % mod;
}
printf("%I64d\n", ans);
return ;
}
CF 476 div2 C的更多相关文章
- cf 442 div2 F. Ann and Books(莫队算法)
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...
- CF#603 Div2
差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...
- CF R631 div2 1330 E Drazil Likes Heap
LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...
- CF#581 (div2)题解
CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...
- [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)
题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...
- CF 197 DIV2 Xenia and Bit Operations 线段树
线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...
- CF#345 div2 A\B\C题
A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...
- CF R303 div2 C. Woodcutters
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CF 192 Div2
A.Cakeminator 暴搞之,从没有草莓覆盖的行.列遍历 char map[30][30]; int vis[30][30]; int hang[30],lie[30]; int main() ...
随机推荐
- input时间输入框小解
date 年月日 month 年月 week 年周(ios上不可用,android部分会显示当前是第几周) time 时分(ios不显示时/分的字样) datetime 为一输入框,基本 ...
- Controller <-> View 一般视图层级
关于 self.navigationController.view 相信看过 MBProgressHUD 官方例子 HudDemo 代码的同学应该看到过下述代码: 1 HUD = [[MBProgre ...
- 《Windows驱动开发技术详解》之驱动程序的基本结构
驱动对象 每个驱动程序会有唯一的驱动对象与之对应,并且这个驱动对象是在驱动加载的时候被内核中的对象管理程序所创建的.驱动对象用DRIVER_OBJECT数据结构表示,它作为驱动的一个实例被内核加载,并 ...
- JDK1.5与1.6在Override上的区别
@Override是JDK5 就已经有了,但有个小小的Bug,就是不支持对接口的实现,认为这不是Override 而JDK6 修正了这个Bug,无论是对父类的方法覆盖还是对接口的实现都可以加上@Ove ...
- ntity Framework技巧系列之四 - Tip 13 – 15
提示13. 附加一个实体的简单方式 问题: 在早先的一些提示中,我们讨论了使用Attach来加载一个处于未改变(unchanged)状态的东西到ObjectContext从而避免进行查询的开销. 如果 ...
- cornerstone 怎么使用
Cornerstone的逻辑很清晰,界面打开后,左边栏上下分开,上面是working copies的列表,下面是REPOSITORIES的列表.常见的功能基本上跟windows一样,在上下文中可以得到 ...
- MULE-ET0 、 ET1、ET2、PT1、PT2
设计验证阶段中的五个样车试制概念 骡子车( mule car ) ET0 第一轮设计工程样车试制 ET1 第二轮设计工程样车试制 ET2 第一轮产品工装样车试制 PT1 第二轮产品工装样车试制 PT2 ...
- weblogic 密码加密
先启动域:
- C#抓取页面时候,获取页面跳转后的地址
static string fanhuiurl(string cahxunurl) { string url = ""; HttpWebRequest req = (HttpWeb ...
- WinForm 子窗体在父窗体范围内移动,不能出父窗体 摘自于网络
详细解释:1, 主窗体Form1属性IsMdiContainer设为True,并添加ToolStrip控件, Toolstrip中添加一个按钮toolStripButton1. 2,添 ...