Codeforces Round #272 (Div. 2) C. Dreamoon and Sums 数学
C. Dreamoon and Sums
题目连接:
http://www.codeforces.com/contest/476/problem/C
Description
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 Input
1 1
Sample Output
0
Hint
题意
求有满足条件的数的和,条件是x/b / x%b = b,问你x有多少种可能的选择
题解:
把式子的分母移过去,然后就可以枚举了
然后发现枚举实际上是可以O(1)计算的……
代码
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
long long a,b,x,y,sum;
int main()
{
cin>>a>>b;
x=(b*(b-1)/2)%mod;
y=(a*(a+1)/2)%mod;
sum=(x*((y*b)%mod+a)%mod)%mod;
printf("%lld\n",sum);
}