Codeforces Round #272 (Div. 2) C. Dreamoon and Sums 数学
2016-10-16 14:22
701 查看
C. 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 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?
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
output
input
output
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}.
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 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?
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}.
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #define eps 1e-14 const int N=1e5+10,M=1e6+10,inf=1e9+10,mod=1e9+7; int main() { ll a,b; scanf("%lld%lld",&a,&b); ll ans=0; for(ll i=1;i<b;i++) { ans=ans+(a*((i*b+i)%mod))%mod+(((b*i)%mod)*((a*(a- 1)/2)%mod))%mod; ans%=mod; } printf("%lld\n",ans); return 0; }
相关文章推荐
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)
- Codeforces Round #272 (Div. 2) C Dreamoon and Sums(数学)
- 【Codeforces Round 272 (Div 2)C】【暴力】Dreamoon and Sums 所有除b结果是模b结果[1,a]倍数字之和
- 【Codeforces Round 272 (Div 2)B】【暴力dfs or 组合数】Dreamoon and WiFi 问号填加减方案数使得最后恰好增量为aim
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi 暴力
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (超几何分布)
- Codeforces Round #272 (Div. 2)-B. Dreamoon and WiFi
- Codeforces Round #272 (Div. 2) B Dreamoon and WiFi(简单DP)
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)
- Codeforces Round #280 (Div. 2) E. Vanya and Field (数学GCD)
- Codeforces Round #199 (Div. 2) -- C. Cupboard and Balloons (数学)
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪心、数学)
- 【Codeforces Round 354 (Div 2)E】【数学 多项式除法 讨论】The Last Fight Between Human and AI 多项式除以x-k是否值整除
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
- Codeforces Round #404 (Div. 2) D. Anton and School - 2(组合数学)
- Codeforces Round #275 (Div. 2) B. Friends and Presents 二分+数学
- Codeforces Round #293 (Div. 2) C. Anya and Smartphone 数学题
- Codeforces Round #285 (Div. 1)B. Misha and Permutations Summation(数学+数据结构打脸)
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution 数学
- 【Codeforces Round 332 (Div 2)D】【数学 公式推导】Spongebob and Squares 正方形数量恰好为x个的所有大矩形