题目链接:

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

Examples
input
1 1
output
0
input
2 2
output
8

题意:

计算满足上述要求的数的和,满足要求的数x/b是x%b的k倍,k属于[1,a];

思路:

一个推公式的题,x=b*div+mod;其中div=k*mod;所以x=(b*k+1)*mod;而1<=k<=a;1<=mod<=b-1;
得到公式∑∑(b*k+1)*mod=(∑(b*k+1))*(∑mod)=b*(b-1)/2*(a+a*(a+1)/2*b);
就变成水题了; AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const int mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=1e3+110;
const double eps=1e-12; int main()
{
LL a,b;
read(a);read(b);
LL ans=b*(b-1)/2%mod;
ans=ans*(a+a*(a+1)/2%mod*b%mod)%mod;
cout<<ans<<endl; return 0;
}

  

codeforces 477A A. Dreamoon and Sums(数学)的更多相关文章

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

  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】 A. Dreamoon and Sums

    A. 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 476C】Dreamoon and Sums

    [链接] 我是链接,点我呀:) [题意] 让你求出所有x的和 其中 (x div b)是(x mod b)的倍数 且x mod b不等于0 且(x div b)除(x mod b)的值(假设为k),k ...

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

  7. cf(#div1 A. Dreamoon and Sums)(数论)

    A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input stand ...

  8. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

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

随机推荐

  1. [javaSE] 练习队列线程和对象序列化

    主要练习了队列数据结构,对象序列化和反序列化,多线程操作 import java.io.BufferedReader; import java.io.File; import java.io.File ...

  2. 关于antlr包删除问题

    在建这个网站,用户登录的时候,涉及查询问题,然后就出现了java.lang.NoSuchMethodError: antlr.collections.AST.getLine()I错误,我一脸蒙逼,后来 ...

  3. CSS3边框温故

    1.简介:border属性在CSS1中就已经定义了,用来设置元素边框风格,设置不同的边框.颜色.粗细 2.基本属性,包括三个类型值:(1)border-width:设置元素边框的粗细,默认3~4px( ...

  4. BaseServlet

    1. 目的: 将提升Servlet的处理请求的能力,而不只限于doGet()/doPost()等请求. 让其Servlet能够自己根据请求,从而触发相应的方法进行处理. 2. 具体代码实现: impo ...

  5. c#多线程生产者消费者(手稿)

    屋舍简陋,隔壁的娃娃哭了一晚,心中无恶意纯中性的想,有病就赶紧带孩子去看医生吧,能哭这么久估计孩子真的不舒服.

  6. Underscore学习笔记1

    项目用了很久underscore.每次都是临时查手册,没有系统的研究过,最近有空正好看看 github地址:https://github.com/lily1010/underscore_learn 一 ...

  7. rails provide与content_for的区别

    页面渲染时:provide先执行,但找到一个provide之后就不再查找 content_for 顺序执行,在哪个位置,就等之前的渲染完后才执行.但是要等到所有的content被查找完后一块返回,也就 ...

  8. ABAP 表格控制(Table Control)和步循环

    表格控制(Table Control)和步循环     1.两个标准Demo: SAPMTZ60,SAPMTZ61 2.简介 3.建立Table Control程序的基本流程 4.使用步循环 5.表格 ...

  9. 中国象棋引擎的C#源代码

    以前写的中国象棋引擎的C#源程序,可在VS2010中编译运行,由于个人精力有限,难以完成后续的开发工作,如果谁感兴趣,请关注微信公众号(“申龙斌的程序人生”,ID:slbGTD),发送后台消息“象棋引 ...

  10. iOS 模仿微信的照片选择器

    功能和微信的基本一致. 这个选择器使用了循环方式,保证在浏览图片时内存中只加载最多3张图片.稳定的内存大小,可定义图片尺寸.详细说明在github. 下载地址: https://github.com/ ...