Educational Codeforces Round 5 E. Sum of Remainders (思维题)
题目链接: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可能相等,所以相等的一段等差数列求和。
- //#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 + ;
- vector <LL> myset; //存储x
- LL mod = 1e9 + ;
- int main()
- {
- LL n, m;
- scanf("%lld %lld", &n, &m);
- LL k = min(m, n);
- myset.push_back(k);
- for(LL i = ; 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 = ;
- for(LL i = ; i < myset.size() && myset[i] <= k; ++i) {
- LL temp = myset[i];
- if(cnt) {
- LL num;
- if((temp - cnt) % )
- num = ((temp + cnt + ) / % mod) * ((temp - cnt) % mod) % mod;
- else
- num = ((temp - cnt) / % mod) * ((temp + cnt + ) % 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 ;
- }
Educational Codeforces Round 5 E. Sum of Remainders (思维题)的更多相关文章
- Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学
E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...
- [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)
Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...
- Codeforces - Educational Codeforces Round 5 - E. Sum of Remainder
题目链接:http://codeforces.com/contest/616/problem/E 题目大意:给定整数n,m(1≤n,m≤1013), 求(n mod 1 + n mod 2 + ... ...
- Educational Codeforces Round 7 D. Optimal Number Permutation 构造题
D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...
- Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题
A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...
- Educational Codeforces Round 4 A. The Text Splitting 水题
A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...
- Codeforces Educational Codeforces Round 3 B. The Best Gift 水题
B. The Best Gift 题目连接: http://www.codeforces.com/contest/609/problem/B Description Emily's birthday ...
- Educational Codeforces Round 14 A. Fashion in Berland 水题
A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...
- Educational Codeforces Round 13 D. Iterated Linear Function 水题
D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...
随机推荐
- 51nod1262 扔球
相关讨论里的答案:(by mint_my ) 1.反弹n次,那起点S,每次反弹点,终点S共连接n+1条边,那么原问题变为从S走n+1条边回到S,为令n=n+12.设步长为a条边,gcd(a,n)==1 ...
- ASP.NET vs MVC vs WebForms
许多ASP.NET开发人员开始接触MVC认为MVC与ASP.NET完全没有关系,是一个全新的Web开发,事实上ASP.NET是创建WEB应用的框架而MVC是能够用更好的方法来组织并管理代码的一种更高级 ...
- UITableView中的(NSIndexPath *)indexPath
indexPath 用来指示当前单元格,它的row方法可以获得这个单元格的行号,section方法可以获得这个单元格所处的区域号
- WEBUS2.0 In Action - 搜索操作指南 - (3)
上一篇:WEBUS2.0 In Action - 搜索操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(4) 3. 评分机制 (Webus.Search.IHitSc ...
- activiti参考5-任务TASK
一.概要 1,设计TASK的表主要是:ACT_RU_TASK,ACT_HI_TASKINST(见参考-activiti表): 2,任务主要有:人工任务(usertask),服务任务(serviceta ...
- 【英语】Bingo口语笔记(28) - 表示“秘密”
- WCF tcpTrace.exe配置
Web.config <?xml version="1.0" encoding="utf-8"?> <configuration> &l ...
- 如何定义java中的类
3步走,如下示例代码所示: package com.imooc; //1.定义一个类 public class Telphone { //2.属性(成员变量)有什么 float screen; flo ...
- Shell教程3-Shell特殊变量
前面已经讲到,变量名只能包含数字.字母和下划线,因为某些包含其他字符的变量有特殊含义,这样的变量被称为特殊变量. 例如,$ 表示当前Shell进程的ID,即pid,看下面的代码: $echo $$ ...
- windowsphone8.0 iso 下载地址
中文版http://download.microsoft.com/download/F/5/6/F56AD199-EF12-43C7-8551-C095394D3B32/fulltril30/iso/ ...