题目链接

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+)/%mod)*b%mod+a)%mod*(b*(b-)/%mod))%mod ;
printf("%I64d\n",sum) ;
}
return ;
}

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

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

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

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

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

    题目链接 这个题取模的时候挺坑的!!! 题意:div(x , b) / mod(x , b) = k( 1 <= k <= a).求x的和 分析: 我们知道mod(x % b)的取值范围为 ...

  5. Codeforces Round #272 (Div. 2) E. Dreamoon and Strings 动态规划

    E. Dreamoon and Strings 题目连接: http://www.codeforces.com/contest/476/problem/E Description Dreamoon h ...

  6. Codeforces Round #272 (Div. 2) D. Dreamoon and Sets 构造

    D. Dreamoon and Sets 题目连接: http://www.codeforces.com/contest/476/problem/D Description Dreamoon like ...

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

  8. Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs 水题

    A. Dreamoon and Stairs 题目连接: http://www.codeforces.com/contest/476/problem/A Description Dreamoon wa ...

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

随机推荐

  1. 一个靠谱的maven仓库镜像地址

    <mirror>   <id>sprintio</id>  <mirrorOf>central</mirrorOf>  <name&g ...

  2. 关于Gateway

    为什么要有gateway?就是因为如果没有,很多的功能需要在在每个微服务中都实现,这样成本很高.

  3. bzoj 2784 时间流逝 —— 树上高斯消元

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2784 其实转移是一棵树,从根到一个点表示一种能量圈状态,当能量值大于 T 是停止,也就是成为 ...

  4. Jenkins的用户管理

    用户管理入口 Jenkins首页有一个用户,但是只能从那查看用户列表和信息,管理用户的入口在Jenkins->系统管理->管理用户 新建用户 在管理用户左侧有一个新增用户,点击后按照表单填 ...

  5. DHCP(三)

    选择阶段:即DHCP客户端选择IP地址的阶段.如果有多台DHCP服务器向该客户端发来DHCP Offer报文,客户端只接受第一个收到的DHCP Offer报文,然后以广播方式发送DHCP Reques ...

  6. swift(Object Storage对象存储服务)(单节点)

    # 在部署对象存储服务(swift)之前,你的环境必须包含身份验证服务(keystone); # keystone需要MySQL数据库,Rabbitmq服务,Memcached服务; # 内存:4G ...

  7. list map set 集合的区别

    Java中的集合包括三大类,它们是Set.List和Map,它们都处于java.util包中,Set.List和Map都是接口,它们有各自的实现 类.Set的实现类主要有HashSet和TreeSet ...

  8. chkdsk工具怎么修复

    对于一些硬盘存储问题,即使windows自带的系统工具,也可以将其修复,比如chkdsk程序.请阅读下文,了解如何使用chkdsk来修复简单的硬盘问题. 工具/原料 windows7 chkdsk 方 ...

  9. [019] Android平台调用WebService详解

    http://blog.csdn.net/lyq8479/article/details/6428288/ http://www.cnblogs.com/gzggyy/archive/2011/06/ ...

  10. 前端学习笔记一:什么是W3C?

    俗话说好记性不如烂笔头,最近在学习前端技术,一些理论性的知识虽然理解,但有时确不能精准的用语言表述出来,那就索性记下来吧,以备以后时常查看: 我们平时说的W3C,其实是World Wide Web C ...