codeforces 616E Sum of Remainders 数学公式转化
来源:互联网 发布:ubuntu kylin 双显卡 编辑:程序博客网 时间:2024/06/06 04:33
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.
Example
Input
3 4
Output
4
Input
4 4
Output
1
Input
1 1
Output
0
题意
给你两个数n,m
问你n % 1 + n % 2 + … + n% m为几
公式化简 n%i=n-n/i*i 那么就要求 n * m - sum(n/i * i) (i从1到m)
由于 当到达i的时候 从i到 n/(n/i) 的 n/i 的值是一样的 因为如果说 n/i 得到了一个因子的下界,那么n/这个因子。则是这个因子的上界。那么就可以那个求和公式求每一段了。
求得过程有些坑点需要注意,首先是注意m的大小,m的大小可能位于n的两个因子之间
然后是,求和公式那里也需要先求下余,再算乘法,这样就需要注意因为有个除2,所以要判断用哪一项能整除2,除完后再求余
#include <bits/stdc++.h>using namespace std;typedef long long ll;const ll mod=1e9+7;int main(){ long long n,m; cin>>n>>m; ll all = (n%mod)*(m%mod); all%=mod; long long res=0; ll t=min(n,m); for(ll i=1;i<=t;i++) { ll l=i; ll r=min((n/(n/i)),m); long long num=r-l+1; long long sw=(l+r); if(sw%2==0) sw/=2; else num/=2; num%=mod,sw%=mod; ll sum=(num%mod)*(sw%mod);//这里不取模居然不行。。好奇怪 sum%=mod; sum*=(n/i); sum%=mod; res+=sum; res%=mod; i=r; } res%=mod; cout<<(all-res+mod)%mod<<endl;}
- codeforces 616E Sum of Remainders 数学公式转化
- codeforces 616E Sum of Remainders(数学公式转化 较难)
- Codeforces 616E Sum of Remainders
- codeforces 616E - Sum of Remainders
- Codeforces 616E - Sum of Remainders
- 【数论】【分块】【乱搞】codeforces 616E Sum of Remainders
- Codeforces 616E Sum of Remainders 【数学分块】
- CodeForces 616E Sum of Remainders(数论)
- Educational Codeforces Round 5 E. Sum of Remainders 数论
- Educational Codeforces Round 5 E. Sum of Remainders(数学)
- Codeforces educational round 5. E Sum of Remainders 数论 分块
- Educational Codeforces Round 5 E. Sum of Remainders
- Educational Codeforces Round 5-E. Sum of Remainders
- CodeForces - 616E Sum of Remainders (数论)大数取余求和 好题
- E. Sum of Remainders (数学)★
- Educational Codeforces Round 5 E. Sum of Remainders 思维 数学转换
- CF-edu#5 E - Sum of Remainders -数学-枚举
- Codeforces 616E Sum Of Reminders
- mui中h5清除缓存页面的办法
- Mongodb中数据聚合之聚合管道aggregate
- 从输入网址到显示网页,这个过程究竟发生了什么?
- Windows平台安装Beautiful Soup
- JDBC连接数据库
- codeforces 616E Sum of Remainders 数学公式转化
- 京东笔试题3
- 附件打包 一键下载
- sql获取单月天数,当年天数
- numpy 使用技巧
- java匿名内部类
- Kafka快速上手教程 2
- java.lang.NoSuchMethodError: org.springframework.beans.factory.xml...setEnviro问题解决方法
- 线性表学习(3)