题目链接: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. JAVA规则引擎 -- Drools

    Drools是一个基于java的规则引擎,开源的,可以将复杂多变的规则从硬编码中解放出来,以规则脚本的形式存放在文件中,使得规则的变更不需要修正代码重启机器就可以立即在线上环境生效. 本文所使用的de ...

  2. Matlab---size,length和numel函数的用法

    size:获取数组的行数和列数 length:数组长度(即行数或列数中的较大值) numel:元素总数. 1.size()函数 s=size(A),当只有一个输出参数时,返回一个行向量,该行向量的第一 ...

  3. VPS技术介绍以及分析

    VPS的全称为Virtual Private Server,叫做虚拟专用服务器(Godaddy称之为Virtual Dedicated Server,VDS).就是利用各种虚拟化手段把单台物理服务器虚 ...

  4. php 获取指定日期所在月份的最后一天

    本文引用来自 http://hi.baidu.com/yflife/item/fd00ef142c5967fcdceeca84 php 获取指定月最后一天: <?phpfunction gett ...

  5. 自定义视图一:扩展现有的视图,添加新的XML属性

    这个系列是老外写的,干货!翻译出来一起学习.如有不妥,不吝赐教! 简介 这个系列详细的介绍了如何穿件Android自定义视图.主要涉及的内容有如何绘制内容,layout和measure的原理,如何继承 ...

  6. socket基础函数(2)

    http://www.cnblogs.com/RascallySnake/archive/2013/07/11/3185071.html   一.select  winsock中 #include & ...

  7. BroadcastReceiver应用详解

    今天我们来讲一下Android中BroadcastReceiver的相关知识. BroadcastReceiver也就是“广播接收者”的意思,顾名思义,它就是用来接收来自系统和应用中的广播. 在And ...

  8. propertyGrid控件 z

    1.如果属性是enum类型,那么自然就是下拉的. 2.如果是你自定义的下拉数据,那么需要用到转换属性标签TypeConverter 参见: http://blog.csdn.net/luyifeini ...

  9. 搭建XMPP协议,实现自主推送消息到手机

    关于服务器端向Android客户端的推送,主要有三种方式: 1.客户端定时去服务端取或者保持一个长Socket,从本质讲这个不叫推送,这是去服务端拽数据.但是实现简单,主要缺点:耗电等 2.Googl ...

  10. 将war包布署在本地tomcat上

    1.把war包解压到..webapps目录下 2. 修改server.xml文件,在host节点中添加 <Context docBase="C:\Users\bai\Desktop\s ...