C. Dreamoon and Sums
Dreamoon loves summing up something for no reason. One day he obtains 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 was some integer number in range< C13>[1, a].
By we denote the quotient of the integer division of x and y. By we denote the remainder of the integer division of x andy. You can read more about these operations here: Http://goo.gl/AcsXhT.
The answer may is large, so please print its remainder modulo 1 007 (9 + 7). Can you compute it faster than Dreamoon?
Input
The single line of the input contains integers a, b (1≤ a, b ≤10 7).
Output
Print A single integer representing the answer modulo 1 007 (9 + 7).
Sample Test (s)
input
1 1
Output
0
Note
For the first sample, there was no nice integers because was always zero.
For the second sample, the set of nice integers is {3, 5}.
Test Instructions : For you, A, B, now all x satisfies the x sum of the div (x,b)/mod (x,b) =k (1<=k<=a).
Puzzle: Set Y=div (X,b), Z=mod (X,b),
Can get
Y=z*k,y*b+z=x, United
(kb+1) Z=x,
The sum formula is used below,
Then assume K is constant, get x=b (b-1) * (kb+1)/2,
Finally k reverts to the variable, gets x=b (b-1)/2*[(1+a) A*b/2+a]
///1085422276#include <bits/stdc++.h>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))inline ll read () {ll x=0, f=1; CharCh=GetChar (); while(ch<'0'|| Ch>'9') { if(ch=='-') f=-1; CH=GetChar (); } while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); } returnx*F;}//****************************************ll mod =1000000007;#defineMAXN 100000+5ll A, B;intMain () {a=read (), b=read (); A= ((b* (* (A +1)/2) (%mod)%mod+a)%mod;b= (b* (b-1))/2)%MoD; cout<< (a*b)%mod<<Endl; return 0;}
Code
Codeforces Round #272 (Div. 2) C. Dreamoon and Sums mathematical push formula