Codeforces 476C Dreamoon and Sums【思维】

来源:互联网 发布:linux按时间分割log 编辑:程序博客网 时间:2024/05/22 06:38

A. Dreamoon and Sums
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 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).

Examples
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}.


题目大意:给你a,b,让你找所有X,满足X/b/X%b==K,(1<=K<=a,X%b!=0)


思路:


1、

①考虑到x%b的值可能为1,2,3,4..........b-1。

②再考虑到X/B:

对应如果X%b的值为1,那么对应X/b的值可行有:1,2,3,4............a,那么对应X的值可行有:b+1,2b+1,3b+1,4b+1................a(b-1)+1.

对应如何X%b的值为2,那么对应X/b 的值可行有:2,4,6,8...........2a,那么对应X的值可行有:2b+1,4b+1,6b+1,8b+1...............2a(b-1)+1

.....................依次类推。


2、那么累加和就是:

【1<=i<b】output+=a*(1+a)/2*i*b+a*i;


3、注意取模姿势。


Ac代码:

#include<stdio.h>#include<string.h>using namespace std;#define mod 1000000007#define ll __int64int main(){    ll a,b;    while(~scanf("%I64d%I64d",&a,&b))    {        ll output=0;        for(ll i=1;i<b;i++)        {            output=(output+a*i)%mod;            ll tmp=(1+a)*a/2%mod;            tmp=i*tmp%mod;            tmp=tmp*b%mod;            output=(output+tmp)%mod;        }        printf("%I64d\n",output);    }}



0 0
原创粉丝点击