题目链接: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. 阿里云linux服务器安装Phalcon-----"phalcon Volt directory can't be written" "gcc: internal compiler error: Killed (program cc1)"

    这里特别蛋疼的一件事是官方英文文档和中文文档命令参数略有不同 中文文档: //通用平台下安装指定的软件包: sudo yum install git gcc make pcre-devel php-d ...

  2. 07_js走路小游戏

    <html> <head> <!-- 不做了,思路: 按enter键停止,将xs,ys替换为0,再次按,判断xs和ys是否为0,是的话,讲根据fx给xsys赋值. 实现鼠 ...

  3. Android 框架简介--Java环境(转)

    ==========================上=========================== 这里简单的介绍了Android的java环境基础,在后面一节中会结合具体的实例来理解这一节 ...

  4. erl0005 - mnesia 分布式部署

    http://www.iteye.com/topic/643187 1.启动两个互通的节点a.b: 2.在a节点net_adm:ping(b) 查看ab之间是否联通(nodes()). 3.在保持通的 ...

  5. php flock注意事项

    对于实际的运用,必须将其添加到所有使用的文件脚本中 但注意:其函数无法再NFS或其他网络文件系统中使用也无法在多线程服务器API中使用.

  6. 【英语】Bingo口语笔记(53) - 口语中不可望文生义的词语

  7. 关于"user.dir"的认识

    最近阅读了一些tomcat源码,看到tomcat在读取jar包外配置文件,是将“user.dir”的路径作为home path文件即 通过System.getProperty("user.d ...

  8. 计算机网络——TCP/IP协议族详解

    一.OSI七层协议体系结构域TCP/IP四层体系结构对比 ISO/OSI模型,即开放式通信系统互联参考模型(Open System Interconnection Reference Model),是 ...

  9. Hadoop学习总结之四:Map-Reduce的过程解析

    转:http://www.cnblogs.com/forfuture1978/archive/2010/11/19/1882268.html

  10. TextView及其子类

    1.TextView控件(TextView是EditView.Button等类的父类) <1>android:id   给当前控件定义了一个唯一标识符 <2>android:l ...