Codeforces 476C Dreamoon and Sums

来源:互联网 发布:宫颈癌疫苗副作用 知乎 编辑:程序博客网 时间:2024/05/22 05:16
Dreamoon loves summing up something for no reason. One day he obtains two integersa and b occasionally. He wants to calculate the sum of allnice integers. Positive integer x is called nice if and, wherek is some integer number in range [1, a].

By we denote thequotient of integer division of x and y. By we denote theremainder of integer division of x and y. 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 a,b (1 ≤ a, b ≤ 107).

Output

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

Sample test(s)
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}.


解题思路:这题就是一个简单的推导公式的题目,将x%b=1-->b-1和a=1-->a所有情况算出的x值加起来,注意横线代表的是div(x,b)%mod(x,b)必须等于0,不要和计算机中的除法弄混了,这题公式一会儿推导出来了,就是把该除法当成计算机中的除法,然后导致各种WA,最后此发现自己脑残了,mark以下,下次遇到这种情况得注意。

/* ***********************************************Author        :sponge_wxyCreated Time  :2015年09月06日 星期日 09时49分38秒File Name     :476C.cpp************************************************ */#include <cmath>#include <ctime>#include <cstdio>#include <cstdlib>#include <cstring>#include <cctype>#include <iostream>#include <string>#include <vector>#include <deque>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <utility>#include <numeric>#include <algorithm>#include <functional>using namespace std;typedef long long ll;const int inf = 0x3f3f3f3f;const ll  INF = 0x3f3f3f3f3f3f3f3fLL;const double pi = acos(-1.0);const int mod = 1000000000 + 7;ll cal_one(ll x) {return (x + 1) * x / 2;}ll cal_two(ll x) {return x * (x + 1) * (2 * x + 1) / 6;}int main() {ll a, b;cin >> a >> b;//ll x = b * cal_two(b-1);//ll y = b * (cal_two(b-1)-cal_one(b-1))/2 + cal_two(b-1);//cout << cal_one(a) * x + a * y << endl;//cout << cal_one(a) * (cal_two(b-1) + a * (cal_two(b-1)-cal_one(b-1))/2) << endl;/* * int ans = 0;for(int k = 1; k <= a; ++k) {for(int y = 1; y < b; ++y) {ans += k * b * y * y + cal_one(y-1) * b + y * y;}}printf("%d\n", ans);*/ll ans = 1;ans = ans * b * (b - 1) / 2;ans %= mod;ll t = (1+a)*a/2;t %= mod;t = b * t % mod;t += a;ans = ans * t % mod;cout << ans << endl;//ans = ans * (a + b*((1+a)*a/2)%mod) % mod;//cout << ans << endl;return 0;}


0 0