Codeforces 476C Dreamoon and Sums

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 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_wxy
Created 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值