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 ...
随机推荐
- linux之 crontab 定时任务
crontab命令被用来提交和管理用户的需要周期性执行的任务,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务工具,并且会自动启动crond进程,crond进程每分钟会定期检查 ...
- MinGW下载并配置gcc/g++编译环境
本文将讲解如何下载MinGW并配置gcc\g++编译环境 一.下载MinGW 在MinGW官网中下载“mingw-get-setup.exe” 官网传送门:http://www.mingw.org/ ...
- Java-Runoob:Java 教程
ylbtech-Java-Runoob:Java 教程 1.返回顶部 1. Java 教程 Java 是由Sun Microsystems公司于1995年5月推出的高级程序设计语言. Java可运行于 ...
- 类的特殊成员方法,类的起源type, metaclass
1.__doc__表示类的描述信息 2. __module__ 和 __class__ __module__ 表示当前操作的对象在那个模块 __class__ 表示当前操作的对象的类是什么 ...
- 转载:细说oracle 11g rac 的ip地址
本文转载自:细说oracle 11g rac 的ip地址 http://blog.sina.com.cn/s/blog_4fe6d4250102v5fa.html 以前搭建oracle rac的时候( ...
- jQuery笔记——Ajax
Ajax 全称为:“Asynchronous JavaScript and XML”(异步 JavaScript 和 XML), 它并不是 JavaScript 的一种单一技术,而是利用了一系列交互式 ...
- .net 连接ORACLE中文显示乱码解决方案
FYI由于历史的原因,早期的oracle没有中文字符集(如oracle6.oracle7.oracle7.1),但有的用户从那时起就使用数据库了, 并用US7ASCII字符集存储了中文,或是有的用户在 ...
- 老外畅想C# 5.0这个可以有
C# 5.0 - not quite there yet! 老外大胆的YY了一下,感觉挺有意思转发过来. 回顾C#发展的历史,C#1.0模仿了Java,并保留了C/C++的一些特性如struct,新学 ...
- vbs获取html内容
Dim content,name,password,arr,pos msg1="请输入ip和端口号地址"&chr(13)&chr(10)&"如ht ...
- 解决mybatis中转义字符的问题
xml格式中不允许出现类似“>”这样的字符,有如下两种解决方法 方法一:使用转义字符 SELECT * FROM test WHERE 1 = 1 AND start_date <= CU ...