题目链接: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可能相等,所以相等的一段等差数列求和。

  1. //#pragma comment(linker, "/STACK:102400000, 102400000")
  2. #include <algorithm>
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cstdio>
  7. #include <vector>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <list>
  11. #include <set>
  12. #include <map>
  13. using namespace std;
  14. typedef __int64 LL;
  15. typedef pair <int, int> P;
  16. const int N = 1e5 + ;
  17. vector <LL> myset; //存储x
  18. LL mod = 1e9 + ;
  19.  
  20. int main()
  21. {
  22. LL n, m;
  23. scanf("%lld %lld", &n, &m);
  24. LL k = min(m, n);
  25. myset.push_back(k);
  26. for(LL i = ; i*i <= n; ++i) {
  27. myset.push_back(i);
  28. if(i * i != n) {
  29. myset.push_back(n/i);
  30. }
  31. }
  32. sort(myset.begin(), myset.end());
  33. LL ans = (n%mod)*(m%mod)%mod, cnt = ;
  34. for(LL i = ; i < myset.size() && myset[i] <= k; ++i) {
  35. LL temp = myset[i];
  36. if(cnt) {
  37. LL num;
  38. if((temp - cnt) % )
  39. num = ((temp + cnt + ) / % mod) * ((temp - cnt) % mod) % mod;
  40. else
  41. num = ((temp - cnt) / % mod) * ((temp + cnt + ) % mod) % mod;
  42. num = ((n / temp) % mod * num) % mod;
  43. ans = ((ans - num) % mod + mod) % mod;
  44. }
  45. else {
  46. ans = (ans - n) % mod;
  47. }
  48. cnt = temp;
  49. }
  50. printf("%lld\n", (ans + mod) % mod);
  51. return ;
  52. }

Educational Codeforces Round 5 E. Sum of Remainders (思维题)的更多相关文章

  1. 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 ...

  2. [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 ...

  3. 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 + ... ...

  4. Educational Codeforces Round 7 D. Optimal Number Permutation 构造题

    D. Optimal Number Permutation 题目连接: http://www.codeforces.com/contest/622/problem/D Description You ...

  5. 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 ...

  6. Educational Codeforces Round 4 A. The Text Splitting 水题

    A. The Text Splitting 题目连接: http://www.codeforces.com/contest/612/problem/A Description You are give ...

  7. 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 ...

  8. Educational Codeforces Round 14 A. Fashion in Berland 水题

    A. Fashion in Berland 题目连接: http://www.codeforces.com/contest/691/problem/A Description According to ...

  9. Educational Codeforces Round 13 D. Iterated Linear Function 水题

    D. Iterated Linear Function 题目连接: http://www.codeforces.com/contest/678/problem/D Description Consid ...

随机推荐

  1. 51nod1262 扔球

    相关讨论里的答案:(by mint_my ) 1.反弹n次,那起点S,每次反弹点,终点S共连接n+1条边,那么原问题变为从S走n+1条边回到S,为令n=n+12.设步长为a条边,gcd(a,n)==1 ...

  2. ASP.NET vs MVC vs WebForms

    许多ASP.NET开发人员开始接触MVC认为MVC与ASP.NET完全没有关系,是一个全新的Web开发,事实上ASP.NET是创建WEB应用的框架而MVC是能够用更好的方法来组织并管理代码的一种更高级 ...

  3. UITableView中的(NSIndexPath *)indexPath

    indexPath 用来指示当前单元格,它的row方法可以获得这个单元格的行号,section方法可以获得这个单元格所处的区域号

  4. WEBUS2.0 In Action - 搜索操作指南 - (3)

    上一篇:WEBUS2.0 In Action - 搜索操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(4) 3. 评分机制 (Webus.Search.IHitSc ...

  5. activiti参考5-任务TASK

    一.概要 1,设计TASK的表主要是:ACT_RU_TASK,ACT_HI_TASKINST(见参考-activiti表): 2,任务主要有:人工任务(usertask),服务任务(serviceta ...

  6. 【英语】Bingo口语笔记(28) - 表示“秘密”

  7. WCF tcpTrace.exe配置

    Web.config <?xml version="1.0" encoding="utf-8"?> <configuration> &l ...

  8. 如何定义java中的类

    3步走,如下示例代码所示: package com.imooc; //1.定义一个类 public class Telphone { //2.属性(成员变量)有什么 float screen; flo ...

  9. Shell教程3-Shell特殊变量

    前面已经讲到,变量名只能包含数字.字母和下划线,因为某些包含其他字符的变量有特殊含义,这样的变量被称为特殊变量. 例如,$ 表示当前Shell进程的ID,即pid,看下面的代码:   $echo $$ ...

  10. windowsphone8.0 iso 下载地址

    中文版http://download.microsoft.com/download/F/5/6/F56AD199-EF12-43C7-8551-C095394D3B32/fulltril30/iso/ ...