Codeforces Round #272 (Div. 2) C. Dreamoon and Sums mathematical push formula

Source: Internet
Author: User
Tags integer division

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.