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 and y. 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 a, b (1 ≤ a, b ≤ 107).

Output

Print a single integer representing the answer modulo 1 000 000 007 (109 + 7).

Sample test(s)
Input
1 1
Output
0
Input
2 2
Output
8
Note

For the first sample, there are no nice integers because is always zero.

For the second sample, the set of nice integers is {3, 5}.

题意:

给你两个整数a,b ,定义这样一个数为漂亮数:

(1) x>0  ;  (2)x%b!=0 ;  (3)  (x/b)/(x%b)=k;  (4)k属于[1,a];

求这样的漂亮数的所有之和。

对于这样题,分析起来其实还是很简单的, 对于求和(sum),我们需要做的第一件事就是确定漂亮数的边界(上限和下限)、由于(3) (x/b)/(x%b)=k

可以得出: x/b = k*(x%b);              x%b的剩余系即{1,2,3,4,5,......b-1}里的最大系;我们不放设定y={1,2,3,4,5,........b-1};

不难得出:  x=k*y*b+y; -->x=(k*b+1)*y 所以可以推断公式:  x=Σ1a (k*b+1)*Σ1b-1 (y);

进一步简化后部分: x=Σ1a (k*b+1)*(b-1)*(b)/2;

所以代码为:

 #include<cstdio>
#include<cstring>
#define LL __int64
#define mod 1000000007
int main()
{
LL a,b;
LL sum;
while(scanf("%I64d%I64d",&a,&b)!=EOF)
{
sum=;
for(LL j=;j<=a;j++)
{
sum+=((j*b)%mod+)%mod;
sum%=mod;
}
LL ans=(((b-)*b)/)%mod;
printf("%I64d\n",(sum*ans)%mod);
}
return ;
}

cf(#div1 A. Dreamoon and Sums)(数论)的更多相关文章

  1. cf(#div1 B. Dreamoon and Sets)(数论)

    B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. codeforces 477A A. Dreamoon and Sums(数学)

    题目链接: A. Dreamoon and Sums time limit per test 1.5 seconds memory limit per test 256 megabytes input ...

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

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

  5. CF 984C Finite or not? (数论)

    CF 984C Finite or not? (数论) 给定T(T<=1e5)组数据,每组数据给出十进制表示下的整数p,q,b,求问p/q在b进制意义下是否是有限小数. 首先我们先把p/q约分一 ...

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

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

  9. cf 450b 矩阵快速幂(数论取模 一大坑点啊)

    Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, ple ...

随机推荐

  1. iOS—最全的真机测试教程

    准备 开发者账号 自从Xcode7 出来之后,一般的真机测试不需要开发者账号,也就不需要看这篇教程,只有app具有“推送”等功能的时候,要真机测试就必须要开发者账号和设置证书.苹果只是让你体验一下它的 ...

  2. DirectX 矩阵

    基础: 下标:第一个下标为该元素所在行的索引,第二个下标为该元素所在列的索引.如下图所示 行向量和列向量:只有单行的向量称为行向量,只有单列的称之为列向量. 相等 维数和元素都相等 数乘(与标量相乘) ...

  3. Windows Live Writer代码高亮插件对比

    一.Paste ASVisual Studio Code 参考:http://www.cnblogs.com/mikelij/archive/2010/11/13/1876199.html 插件下载: ...

  4. 【转载】C++知识库内容精选 尽览所有核心技术点

    原文:C++知识库内容精选 尽览所有核心技术点 C++知识库全新发布. 该知识库由C++领域专家.CSDN知名博客专家.资深程序员和项目经理安晓辉(@foruok)绘制C++知识图谱,@wangshu ...

  5. ubuntu安装miniconda

    系统:ubuntu15.04   64位 wget -c http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh chm ...

  6. How to build a GUI in ROS with Qt / C++

    p { margin-bottom: 0.1in; direction: ltr; line-height: 120%; text-align: left; widows: 2; orphans: 2 ...

  7. 一种json生成html的思路

    输入: [{ tag:"ul", attribute:{ class:"father6" }, property:{ className:"fathe ...

  8. [poj3349]Snowflake Snow Snowflakes(hash)

    Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 37615 Accepted: ...

  9. [转载] 深入理解Linux修改hostname

    原文: http://www.cnblogs.com/kerrycode/p/3595724.html 当我觉得对Linux系统下修改hostname已经非常熟悉的时候,今天碰到了几个个问题,这几个问 ...

  10. sscanf的用法(转)

    队长做上海邀请赛的I题时遇到一个棘手的问题,字符串的处理很麻烦,按传统的gets全部读入的话还要做N多处理,太浪费时间. 回来之后搜了一下sscanf的用法发现可以很好的解决这一类问题,各种百度,转来 ...