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?
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).
题意 : 给你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+)/%mod)*b%mod+a)%mod*(b*(b-)/%mod))%mod ;
printf("%I64d\n",sum) ;
}
return ;
}
Codeforces Round #272 (Div. 1) A. Dreamoon and Sums(数论)的更多相关文章
- Codeforces Round #272 (Div. 2)-C. Dreamoon and Sums
http://codeforces.com/contest/476/problem/C C. Dreamoon and Sums time limit per test 1.5 seconds mem ...
- 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 int ...
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums 数学
C. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #272 (Div. 2) C. Dreamoon and Sums (数学 思维)
题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划
E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...
- Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造
D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...
- Codeforces Round #272 (Div. 2) B. Dreamoon and WiFi dp
B. Dreamoon and WiFi 题目连接: http://www.codeforces.com/contest/476/problem/B Description Dreamoon is s ...
- Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题
A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...
- Codeforces Round #272 (Div. 2) E. Dreamoon and Strings dp
题目链接: http://www.codeforces.com/contest/476/problem/E E. Dreamoon and Strings time limit per test 1 ...
随机推荐
- 【转】数据库范式(1NF 2NF 3NF BCNF)
范式判断流程图 1. 四种范式之间关系 2.第二范式.第三范式.BCNF区别: 2NF:非主键列和主键列之间,是完全依赖于主键,还是依赖于主键的一部分(只依赖某个主键): 3NF:非主键列之间,不存在 ...
- bzoj 3501 PA2008 Cliquers Strike Back——贝尔数
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3501 用贝尔三角形 p^2 地预处理 p 以内的贝尔数.可以模(mod-1)(它是每个分解下 ...
- jmeter --- 测试计划里的元件
1.线程组 线程组元件是任何一个测试计划的开始点.在一个测试计划中的所有元件都必须在某个线程组下.顾名思义,线程组元件控制JMeter执行你的测试计划时候使用的线程数量.对线程组的控制允许你: 设置线 ...
- sed 相关
sed中,a命令是指在匹配的位置后面插入新的内容. c命令是说将在匹配模式空间的指定行用新文本加以替代.
- thinkphp5 设置.htaccess报input file specified的解决方法
先去检查服务器设置,这个网上方法很多就不说了,如果服务器没问题还是报这个错误的话可能和php版本有关 php5.4和以下版本的.htaccess <IfModule mod_rewrite.c& ...
- (转)C# Socket异步通信
本文转载自:http://www.cnblogs.com/llllll/archive/2009/05/13/1455703.html 服务器端 TCPServer 1.使用的通讯通道:socket ...
- org/apache/hadoop/hbase/mapreduce/TableReducer:Unsupported major.minor version52.0
问题详情: 问题原因: <dependency> <groupId>org.apache.hbase</groupId> <artifactId& ...
- 1107 Social Clusters
题意:给出n个人(编号为1~n)以及每个人的若干个爱好,把有一个或多个共同爱好的人归为一个集合,问共有多少个集合,每个集合里有多少个人? 思路:典型的并查集题目.并查集的模板init()函数,unio ...
- PHP读取文件夹数据,并分页
protected function read_all ($dir){ // 确保目录有权限进入 if(!is_dir($dir)) return false; $handle = opendir($ ...
- rpm --import /etc/pki/rpm-gpg/RPM* 有什么用?
今天用yum安装软件,遇到了Could not open/read file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL问题,为了加深印象,特别搜索了RPM-GPG-K ...