题目链接: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 (思维题)的更多相关文章

  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. Couchbase的web管理员后台 查看缓存提示警告 Warning: Editing of document with size more than 2.5kb is not allowed的解决方法

    这个警告仅仅只会发生在web管理员后台,实际在缓存中的数据是不会有影响的(好像默认单个key对应的缓存大小是20M) 但是有时候我们就是想在web后台里面看看到底保存了什么数据,怎么能突破这个限制呢? ...

  2. App开放接口api安全性—Token签名sign的设计与实现

    前言 在app开放接口api的设计中,避免不了的就是安全性问题,因为大多数接口涉及到用户的个人信息以及一些敏感的数据,所以对这些接口需要进行身份的认证,那么这就需要用户提供一些信息,比如用户名密码等, ...

  3. Cookie存储中文报错:java.lang.IllegalArgumentException: Control character in cookie value or attribute.(转)

    项目中做自动登录和保存密码时,Cookie报错Java.lang.IllegalArgumentException,上google查了下 在http://hi.baidu.com/xtxycy/blo ...

  4. 【英语】Bingo口语笔记(68) - come系列

  5. NoSQL架构实践(一)——以NoSQL为辅

    前面<为什么要使用NoSQL>和<关系数据库还是NoSQL数据库>两篇从大体上介绍了为什么要用NoSQL,何时该用NoSQL.经常有朋友遇到困惑,看到NoSQL的介绍,觉得很好 ...

  6. 浅谈C#浅拷贝和深拷贝

    近来爱上一本书<编写高质量代码,改善C#程序的157个建议>,我想很多人都想编写高质量的代码,因为我们不仅仅是码农,更是一名程序员. 从今天开始,我将每天和大家分享这本书中的内容,并加上自 ...

  7. 如何脱离SDK,使用DW5.5和phonegap以及JQMobile搭建开发环境

    也许有些人是学C++出身,对于Java几乎不了解.一时心血来潮想学学android开发,于是下载了Eclipse,安装了SDK,有模有样的学习起来.也许是懒惰了,对于java一直总是提不起精神.于是确 ...

  8. Linux下ntpdate时间同步

    Linux下ntpdate时间同步 Ntp服务器配置(暂略,以后整理) 时间同步方法 同步命令               # ntpdate ntp服务器域名或IP           例:# nt ...

  9. Linux makefile教程之make运行八[转]

    make 的运行 —————— 一 般来说,最简单的就是直接在命令行下输入make命令,make命令会找当前目录的makefile来执行,一切都是自动的.但也有时你也许只想让 make重编译某些文件, ...

  10. Excel 绘制图表,如何显示横轴的数据范围

    右键点击X坐标轴,然后选中“设置图表区域格式”,然后在“坐标轴选项”--“区域”处设置X轴范围. 备注,这种方式仅使用与第一列时日期时间类型的数据. 应用场景 当,选择有两列数据,第一列为横轴数据,第 ...