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 ...
随机推荐
- 对实体 "useSSL" 的引用必须以 ';' 分隔符结尾。
<property name="connection.url">jdbc:mysql://127.0.0.1/cache?useUnicode=true&cha ...
- bzoj 4453 cys就是要拿英魂!——后缀数组+单调栈+set
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4453 询问离线,按R排序. 发现直接用 rk[ ] 的错误情况就是前面的某个位置 j 和自己 ...
- Python学习之变量的作用域
学习地址:http://www.jianshu.com/p/17a9d8584530 1.变量作用域LEGB 1.1变量的作用域 在Python程序中创建.改变.查找变量名时,都是在一个保存变量名的空 ...
- What’s that ALUA exactly?
What’s that ALUA exactly? 29 September, 20098 Comments Of course by now we have all read the excelle ...
- 融云rongCloud聊天室的使用
融云提供了两种途径的接口, 一个是app端,一个是服务器端的. app端 1.连接融云,监听消息 rong = api.require('rongCloud2'); rong.init(functio ...
- Dynamics CRM 2011 FetchXml QueryExpression LINQ
Dynamics CRM 2011支持三种查询语句 FetchXml QueryExpression LINQ 查询 功能 保存 FetchXml 支持QueryExpression的所有功能,额外支 ...
- GitHub in vs2010、vs2013
GitHub在使用上大致和其他源代码管理工具一样,个人源代码管理和分享一大利器,而且vs2010和vs2013配置也没有任何区别,简单做了一下图文配置说明 一.注册github 1.github.co ...
- 安全测试回顾(一)补充:burp 的基本操作
浏览器设置; 拦截请求: Spider 伪造请求: 对这个url 伪造请求 拦截一个页面后,进入攻击模块 sniper 两个参数值 保证一个不变 另一个 进行枚举 battering ram 两个 ...
- 什么是Ajax和JSON,它们的优缺点
什么是Ajax??? 术语Ajax用来描述一组技术,它使浏览器可以为用户提供更为自然的浏览体验. Ajax它是“Asynchronous JavaScript + XML的简写” 定义Ajax: Aj ...
- requests的响应返回值显示content和text方法的区别
requests的get或者post请求,返回的响应response获取方法:content和text content用于获取图片,返回二进制数据 text用于获取内容,返回的是unicode解码字符 ...