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

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

Output

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

题意 : 给你a,b。让你找出符合以下条件的x,div(x,b)/mod(x,b)=k,其中k所在范围是[1,a],其中mod(x,b)!= 0.然后将所有符合条件的x加和,求最后的结果

官方题解 :

If we fix the value of k, and let d = div(x, b), m = mod(x, b), we have :
d = mk
x = db + m
So we have x = mkb + m = (kb + 1) * m.
And we know m would be in range [0, b - 1] because it‘s a remainder, so the sum of x of that fixed k would be .
Next we should notice that if an integer x is nice it can only be nice for a single particular k because a given x uniquely definesdiv(x, b) and mod(x, b).
Thus the final answer would be sum up for all individual k which can be calculated in O(a) and will pass the time limit of 1.5 seconds.
Also the formula above can be expanded to .

#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std ;
#define mod 1000000007

int main()
{
    long long a,b ;
    while(~scanf("%I64d %I64d",&a,&b)){
        //    printf("%I64d\n",a*(a+1)/2) ;
        long long sum = (((a*(a+1)/2%mod)*b%mod+a)%mod*(b*(b-1)/2%mod))%mod ;
        printf("%I64d\n",sum) ;
    }
    return 0 ;
}

时间: 2024-10-14 01:05:51

Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)的相关文章

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) 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) 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) D.Dreamoon and Sets 找规律

D. Dreamoon and Sets Dreamoon likes to play with sets, integers and .  is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for

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)

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

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)

Codeforces Round #272 (Div. 2) Dreamoon and WiFi 暴力

B. Dreamoon and WiFi Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: Go 1 unit towards the