CF_476C_DreamoonAndSums
来源:互联网 发布:ubuntu查看硬盘大小 编辑:程序博客网 时间:2024/06/03 13:03
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 andy. 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,那么其实满足条件的数就是下面这些数(列写下就好了)
b+1 2b+1 3b+1 ………… ab+1
2b+2 4b+2 6b+2 ………… 2ab+2
3b+3 6b+3 9b+3 ………… 3ab +3
b(b-1)+(b-1) 2(b-1)b+(b-1) 3(b-1)b+(b-1) …………a(b-1)b+(b-1)
横着每行a个数,一共b-1行 求和就可以了
#include <iostream>#include <stdio.h>using namespace std;typedef long long LL;const int MO=1e9+7;int main(){ LL a,b; scanf("%I64d %I64d",&a,&b); LL ans1=(b*(b-1)/2)%MO; LL ans2=((((a*(a+1))/2)%MO*b)%MO*ans1)%MO; LL ans=((ans1*a)%MO+ans2)%MO; printf("%I64d\n",ans); return 0;}