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. 关于float的感悟

    给元素设置了float样式后,最终的结果是: 1:这个元素漂浮起来, 2:其他的元素位置可以视为 这个元素不存在 的时候的位置:但是float样式还是对整个页面有所影响 3:float的影响就是他附近 ...

  2. lncRNA研究

    ------------------------------- Long noncoding RNAs are rarely translated in two human cell lines. ( ...

  3. hdu 3033 I love sneakers! 分组背包

    I love sneakers! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. Android内存泄露测试

    Android性能测试过程中的一些常用命令: CPU: adb shell top -n | grep "+PackageName 内存: adb shell dumpsys meminfo ...

  5. Codeforces Round #198 (Div. 2)

    A.The Wall 题意:两个人粉刷墙壁,甲从粉刷标号为x,2x,3x...的小块乙粉刷标号为y,2y,3y...的小块问在某个区间内被重复粉刷的小块的个数. 分析:求出x和y的最小公倍数,然后做一 ...

  6. iOS - Swift Enum 枚举

    1.Enum 的创建 1.1 标准定义 枚举的定义 enum CompassPoint { case North case South case East case West } enum Plane ...

  7. PHP面向对象(OOP)编程入门教程————如何实例化对象?

    我们上面说过面向对象程序的单位就是对象,但对象又是通过类的实例化出来的,既然我们类会声明了,下一步就是实例化对象了. 当定义好类后,我们使用new关键字来生成一个对象. $对象名称 = new 类名称 ...

  8. Can of Worms 【迭代/线段树】

    题意:一条直线上有n个炸弹,给出每个炸弹的爆炸半径,可以引爆另一个炸弹爆炸.问:每个炸弹爆炸后,最多有几个炸弹一起爆炸? 迭代,用线段树更新. #include <cstdio> #inc ...

  9. Vsftpd服务的搭建

    安装vsftpd服务程序 yum install vsftpd -y Vsftpd的程序与配置文件: 主程序 /usr/sbin/vsftpd 用户禁止登陆列表 /etc/vsftpd/ftpuser ...

  10. ssh免密码登陆及其原理

    ssh 无密码登录要使用公钥与私钥.linux下可以用用ssh-keygen生成公钥/私钥对,下面我以CentOS为例. 有机器A(192.168.1.155),B(192.168.1.181).现想 ...