CodeForces 616E Sum of Remainders(数论)
来源:互联网 发布:高三励志语录知乎 编辑:程序博客网 时间:2024/05/17 05:56
题意:给出n,m,计算sigma(n%i)(1<=I<=m)。
思路:将原式化简成 .
注意到n/I和i最多只能有一项大于sqrt(n),所以分别枚举这两项然后相加。
#include <bits/stdc++.h>#define eps 1e-6#define LL long long#define pii pair<int, int>#define pb push_back#define mp make_pair//#pragma comment(linker, "/STACK:1024000000,1024000000")using namespace std;const int MOD = 1e9+7;LL n, m;LL pow_mod(int a, int b) {if (!b) return 1;LL ans = pow_mod(a, b/2);ans = (ans*ans) % MOD;if (b&1) ans = ans * a % MOD;return ans;}int main(){//freopen("input.txt", "r", stdin);cin >> n >> m;LL ans = n%MOD * (m%MOD) % MOD;m = min(m, n);LL q = (LL)sqrt(n);LL inv = pow_mod(2, MOD-2);for (int i = 1; i <= q; i++) {LL l = min(m, n/(i+1)), r = min(m, n/i);ans = (ans - (l+1+r)%MOD*((r-l)%MOD)%MOD*inv%MOD*i%MOD) % MOD;}q = min(q, m);for (int i = 1; i <= q; i++) ans = (ans - n/i*i) % MOD;if (q == n/q) ans = (ans + n/q*q) % MOD;ans = (ans + MOD) % MOD;cout << ans; return 0;}
0 0
- 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 数论
- Codeforces educational round 5. E Sum of Remainders 数论 分块
- Codeforces 616E Sum of Remainders 【数学分块】
- codeforces 616E Sum of Remainders 数学公式转化
- Educational Codeforces Round 5 E. Sum of Remainders(数学)
- codeforces 616E Sum of Remainders(数学公式转化 较难)
- Educational Codeforces Round 5 E. Sum of Remainders
- Educational Codeforces Round 5-E. Sum of Remainders
- E. Sum of Remainders (数学)★
- Educational Codeforces Round 5 E. Sum of Remainders 思维 数学转换
- Codeforces 678B Remainders Game(数论)
- CF-edu#5 E - Sum of Remainders -数学-枚举
- ActiveX资料收集
- Oracle聊天系统设计
- 为什么开发者不应该在程序中调用sun.*包?
- java 变量初始值
- JSTL函数标签库 fn标签
- CodeForces 616E Sum of Remainders(数论)
- 正则拓展: 匹配大陆和港式身份证
- android 属性文件default.prop与adb
- JAVA中常用IO流类:FileInputStream和FileOutputStream
- ERROR 1201 (HY000):Could not initialize master info structure,ERROR 29 (HY000): File'./web_appdb_的问题
- jstl 格式化时间日期标签讲解
- openwrt创建软件包
- Protobuffer的研究史
- SCSI work flow