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?
The single line of the input contains two integers a, b (1 ≤ a, b ≤ 107).
Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).
1 1
0
2 2
8
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 __int64
int 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);
}
}