http://www.codeforces.com/contest/476/problem/C

 

C. Dreamoon and Sums

time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

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?

Input

The single line of the input contains two integers ab (1 ≤ a, b ≤ 107).

Output

Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).

Examples
input
1 1
output
0
input
2 2
output
8
Note

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的更多相关文章

  1. 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, ...

  2. CF#603 Div2

    差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...

  3. CF R631 div2 1330 E Drazil Likes Heap

    LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...

  4. CF#581 (div2)题解

    CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...

  5. [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)

    题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...

  6. CF 197 DIV2 Xenia and Bit Operations 线段树

    线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...

  7. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

  8. CF R303 div2 C. Woodcutters

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  9. CF 192 Div2

    A.Cakeminator 暴搞之,从没有草莓覆盖的行.列遍历 char map[30][30]; int vis[30][30]; int hang[30],lie[30]; int main() ...

随机推荐

  1. 数组按时间(字符串->Date)排序

    不说了 ,直接上代码.Talk is cheap , show me the code. NSArray *stortedArray = [wkSelf.dataArray sortedArrayUs ...

  2. 安卓Activity组件

     Activity生命周期 熟悉javaEE的朋友们都了解servlet技术,我们想要实现一个自己的servlet,需要继承相应的基类,重写它的方法,这些方法会在合适的时间被servlet容器调用.其 ...

  3. SuperMapPy 批量拼接 GeoTiff影像

    影像拼接工具使用说明 一.影像像素位深检查 1.采用开源库GDAL的gdalinfo.exe读取GeoTiff文件的信息,如类型.投影,范围等. 2.采用DOS脚本遍历所有GeoTiff文件,输出各个 ...

  4. cmd 下登陆ftp及相关操作

    cmd 下登陆ftp及相关操作 2011-08-09 20:34:28|  分类: 小技巧|字号 订阅 一.举例 假设FTP地址为“ 61.129.83.39”(大家试验的时候不要以这个FTP去试,应 ...

  5. 第六节,初识python和字符编码

    程序语言的发展 机器语言 程序语言,最初的计算机语言是机器语言,完全是0和1组成的二进制串  如:01010101 11010101 汇编语言 因为01010101的字符串,冗长,不利于维护,所以产生 ...

  6. 深入理解JAVA的多态性[转]

    昨天看到一个关于多态性的帖子,参考了回帖者的理解,加入了一些自己的看法,整理出来供大家参考,不一定完全正确,欢迎大家批评指正. (一)相关类 class A ...{         public S ...

  7. hdu_3062_Party(2-SAT)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3062/ 题意:2-SAT的裸题 题解:直接上模版 #include<cstdio> #in ...

  8. linux下base命令

    查看base那么命令的帮助: root@OpenWrt:/# basename --help BusyBox v1.22.1 (2015-09-15 16:38:30 CST) multi-call ...

  9. hdu 1166 敌兵布阵(线段树详解)

    Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任 ...

  10. 7.在第4题中Hello.class所在路径下, 输入命令:java Hello.class,会出现什么结果,为什么?

    java Hello已经是加载类了