Educational Codeforces Round 5 E. Sum of Remainders (思维题)
2016-08-10 17:48
399 查看
题目链接:http://codeforces.com/problemset/problem/616/E
题意很简单就不说了。
因为n % x = n - n / x * x
所以答案就等于 n * m - (n/1*1 + n/2*2 ... n/m*m)
在根号n复杂度枚举x,注意一点当m>n时,后面一段加起来就等于0,就不用再枚举了。
中间一段x1 ~ x2 的n/x可能相等,所以相等的一段等差数列求和。
View Code
题意很简单就不说了。
因为n % x = n - n / x * x
所以答案就等于 n * m - (n/1*1 + n/2*2 ... n/m*m)
在根号n复杂度枚举x,注意一点当m>n时,后面一段加起来就等于0,就不用再枚举了。
中间一段x1 ~ x2 的n/x可能相等,所以相等的一段等差数列求和。
//#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <vector> #include <cmath> #include <ctime> #include <list> #include <set> #include <map> using namespace std; typedef __int64 LL; typedef pair <int, int> P; const int N = 1e5 + 5; vector <LL> myset; //存储x LL mod = 1e9 + 7; int main() { LL n, m; scanf("%lld %lld", &n, &m); LL k = min(m, n); myset.push_back(k); for(LL i = 1; i*i <= n; ++i) { myset.push_back(i); if(i * i != n) { myset.push_back(n/i); } } sort(myset.begin(), myset.end()); LL ans = (n%mod)*(m%mod)%mod, cnt = 0; for(LL i = 0; i < myset.size() && myset[i] <= k; ++i) { LL temp = myset[i]; if(cnt) { LL num; if((temp - cnt) % 2) num = ((temp + cnt + 1) / 2 % mod) * ((temp - cnt) % mod) % mod; else num = ((temp - cnt) / 2 % mod) * ((temp + cnt + 1) % mod) % mod; num = ((n / temp) % mod * num) % mod; ans = ((ans - num) % mod + mod) % mod; } else { ans = (ans - n) % mod; } cnt = temp; } printf("%lld\n", (ans + mod) % mod); return 0; }
View Code
相关文章推荐
- Educational Codeforces Round 5 E. Sum of Remainders 思维 数学转换
- Educational Codeforces Round 5 E. Sum of Remainders 数论
- Educational Codeforces Round 5 E. Sum of Remainders(数学)
- Educational Codeforces Round 5-E. Sum of Remainders
- Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学
- Educational Codeforces Round 4 D. The Union of k-Segments 排序,思维
- [Educational Codeforces Round 7]F. The Sum of the k-th Powers
- Educational Codeforces Round 7 F. The Sum of the k-th Powers 拉格朗日插值法
- Educational Codeforces Round 28 Four Segments 前缀和 + 思维
- Educational Codeforces Round 15 E Analysis of Pathes in Functional Graph(倍增)
- Codeforces Round #277.5(Div. 2) C. Given Length and Sum of Digits...【贪心】
- Educational Codeforces Round 15 E. Analysis of Pathes in Functio(倍增)★ ★
- 【Educational Codeforces Round 37 F】SUM and REPLACE
- 【Educational Codeforces Round 2D】【计算几何 圆面积交 模板】Area of Two Circles' Intersection
- Educational Codeforces Round 4 D. The Union of k-Segments 排序
- Codeforces Round #428 (Div. 2) B. Game of the Rows (思维)
- 【Educational Codeforces Round 41 (Rated for Div. 2) D】Pair Of Lines
- Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
- Educational Codeforces Round 37 (Rated for Div. 2)-F-SUM and REPLACE(线段树)
- Educational Codeforces Round 11(A)思维,数学