E. Sum of Remainders
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7).

The modulo operator a mod b stands for the remainder after dividing a by b. For example 10 mod 3 = 1.

Input

The only line contains two integers n, m (1 ≤ n, m ≤ 1013) — the parameters of the sum.

Output

Print integer s — the value of the required sum modulo 109 + 7.

Sample test(s)
input
3 4
output
4
input
4 4
output
1
input
1 1
output
0

题意很好理解,最后求和的时候找找规律就能过;

AC代码:

#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+;
int main()
{
long long n,m;
cin>>n>>m;
long long ans=;
ans=(n%mod)*(m%mod)%mod;
if(m>=n){m=n;}
long long fx,fy,fz,pre=m;
long long s=;
while(pre>)
{
fy=pre;
fz=n/pre;
fx=n/(fz+);
long long r;
if((fy-fx)%==)r=((fx+fy+)%mod)*(((fy-fx)/)%mod);
else r=((fx+fy+)/)%mod*((fy-fx)%mod);
s+=(r%mod)*fz%mod;
s%=mod;
pre=fx;
}
s+=n;
s%=mod;
cout<<(ans-s+mod)%mod<<endl;
return ;
}
 

codeforces 616E Sum of Remainders (数论,找规律)的更多相关文章

  1. Codeforces 616E - Sum of Remainders

    616E Sum of Remainders Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + - + n mod m. As ...

  2. codeforces 616E. Sum of Remainders 数学

    题目链接 给两个数n, m. 求n%1+n%2+.......+n%m的值. 首先, n%i = n-n/i*i, 那么原式转化为n*m-sigma(i:1 to m)(n/i*i). 然后我们可以发 ...

  3. Codeforces 837E Vasya's Function 数论 找规律

    题意:定义F(a,0) = 0,F(a,b) = 1 + F(a,b - GCD(a,b).给定 x 和 y (<=1e12)求F(x,y). 题解:a=A*GCD(a,b) b=B*GCD(a ...

  4. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  5. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  6. Codeforces Round #242 (Div. 2)C(找规律,异或运算)

    一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...

  7. Codeforces H. Malek Dance Club(找规律)

    题目描述: Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律

    Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...

  9. codeforces 622D D. Optimal Number Permutation(找规律)

    D. Optimal Number Permutation time limit per test 1 second memory limit per test 256 megabytes input ...

随机推荐

  1. 解决SlidingMenu和SwipeBackLayout右滑事件冲突问题

    SwipeBackLayout向右滑动关闭当前Activity,SlidingMenu向右滑动则是打开menu部分.在同一个Activity中,当SlidingMenu处于打开状态时,此时向右滑动,事 ...

  2. 【OpenCV & CUDA】OpenCV和Cuda结合编程

    一.利用OpenCV中提供的GPU模块 目前,OpenCV中已提供了许多GPU函数,直接使用OpenCV提供的GPU模块,可以完成大部分图像处理的加速操作. 基本使用方法,请参考:http://www ...

  3. winform里面网页显示指定内容

    今天有个同事问了一下我,怎么在winform里面打开网页啊?我们都是基于C/S的开发,很少接触winform,所以我当时就懵了,实在不知道怎么回答,所以索性说不知道.但是我又想了想,这个应该是个很简单 ...

  4. SharePoint 2013 设置自定义布局页

    在SharePoint中,我们经常需要自定义登陆页面.错误页面.拒绝访问等:不知道大家如何操作,以前自己经常在原来页面改或者跳转,其实SharePoint为我们提供了PowerShell命令,来修改这 ...

  5. 适配iPhone6和iPhone6 Plus

    先对比所有市面上的iPhone设备,然后分析如何适配新的设备,   iPhone4,iPhone4s 分辨率960*640  长宽比1.5iPhone5,iPhone5s  分辨率1136*640   ...

  6. android XMl 解析神奇xstream 四: 将复杂的xml文件解析为对象

    前言:对xstream不理解的请看: android XMl 解析神奇xstream 一: 解析android项目中 asset 文件夹 下的 aa.xml 文件 android XMl 解析神奇xs ...

  7. 在Mac上配置Android adb命令

    一 adb定义: adb(android debug bridge)是android系统中的一种命令行工具,通过它可以和android设备或模拟器通信. 二 在Mac上的配置过程 启动终端 进入当前用 ...

  8. Python学习三---序列、列表、元组

    一.序列 1.1.序列概念 pythn中最基本的数据结构是序列(sequence). 序列中每个元素被分配一个序号-元素索引,第一个索引是0,第二个是1,以此类推.类似JAVA中数组和集合中的下标. ...

  9. PL/SQL基础2(笔记)

    1 第一个PL/SQL的程序 DECLARE BEGIN DBMS_OUTPUT.PUT_LINE('Hello World!'); END; / --2一个简单的PL/SQL程序 DECLARE v ...

  10. Objective-C之用C的字符来处理NSString相关的字符替换和拼接的问题

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...