Codeforces Round #272 (Div. 2) C

题目:

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 boccasionally.
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 theremainder 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 ab (1?≤?a,?b?≤?107).

Output

Print a single integer representing the answer modulo 1?000?000?007 (109?+?7).

Sample test(s)

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

题意分析:

数学题。看懂公式就行了。考虑枚举一下余数, 如果m = x%b 则 x = mk*b+m = m(kb+1)  m可以预处理为所有可能的余数和,注意long long 和取MOD。

代码:

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>

using namespace std;
const int MOD=1000000007;
int main()
{
    long long a,b;
    while(cin>>a>>b)
    {
        long long m=(1+b-1)*(b-1)/2%MOD;
        //cout<<m<<endl;
        long long sum=0;
        {
            for(long long i=1;i<=a;i++)
            {
                sum=(sum%MOD+m*((b*i)%MOD+1)%MOD)%MOD;
            }
        }
        cout<<sum<<endl;
    }
}

时间: 2024-10-12 18:27:56

Codeforces Round #272 (Div. 2) C的相关文章

Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi (超几何分布)

题目链接:Codeforces Round #273 (Div. 2) B. Dreamoon and WiFi 题意:"+"表示前进1个单位,"-"表示后退1个单位,问以0为起点经过S1,S2两个命令后达到的位置相同的概率. 思路:统计"+"和"-"的数量.如果S2中的"+"或者"-"比S1中的多,概率是0.其他条件下,形成的是超几何分布. AC代码: #include <std

Codeforces Round #272 (Div. 2)

A. Dreamoon and Stairs 题意:给出n层楼梯,m,一次能够上1层或者2层楼梯,问在所有的上楼需要的步数中是否存在m的倍数 找出范围,即为最大步数为n(一次上一级),最小步数为n/2+n%2 在这个范围里找即可 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<algorithm> 6 using n

Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)

题目链接 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

Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)

题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 1  - (b-1).那么我们可以从这一点入口来进行解题.. mod (x, b) = 1 时, x  =  b + 1, 2b + 1, 3b + 1..... a * b + 1. mod (x , b) = 2 时, x =  2b + 2, 4b + 2, 6b + 2, ..... 2a * b

Codeforces Round #272 (Div. 2)C. Dreamoon and Sums 数学推公式

C. Dreamoon and Sums 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 numb

Codeforces Round #272 (Div. 2) A

题目: A. Dreamoon and Stairs time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon wants to climb up a stair of n steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number o

Codeforces Round #272 (Div. 2) B

题目: B. Dreamoon and WiFi time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dream

Codeforces Round #272 (Div. 2) D. Dreamoon and Sets (思维 数学 规律)

题目链接 题意: 1-m中,四个数凑成一组,满足任意2个数的gcd=k,求一个最小的m使得凑成n组解.并输出 分析: 直接粘一下两个很有意思的分析.. 分析1: 那我们就弄成每组数字都互质,然后全体乘以k不就行了么…… 然后看了看样例…… 这个该怎么说……我是觉得额这道题的output暴露了数据规律怎么破……我算是看出规律再证明的方式A的这道题 当时我看到22那个样例的时候……在想他干嘛要把22放这里……然后发现 2/4/6/10 14/16/18/22也是行的哇…… 化成乘以k之前的数据……

Codeforces Round #272 (Div. 2) ABCDE

A. Dreamoon and Stairs 题解: 首先写出尽可能2多的步数,然后判断能否%m,不能就加上最小的数使其能%m就行了 代码: #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define se second #define fs first #define LL long long #define CLR(x) memset(x,0,sizeof x)