题目链接

给两个数n, m. 求n%1+n%2+.......+n%m的值。

首先, n%i = n-n/i*i, 那么原式转化为n*m-sigma(i:1 to m)(n/i*i)。

然后我们可以发现  1/4 = 2/4 = 3/4 = 0, 4/4 = 5/4 = 6/4 = 7/4 = 1. 所以可以将这些结果分成很多块, 按块算结果。

注意计算过程中时刻避免爆longlong。

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const ll mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
vector <pair<ll, ll> > v;
ll getsum(ll a, ll b) {
if((b-a)%==) {
return ((b-a)/%mod)*((a+b+)%mod)%mod;
}
return ((a+b+)/%mod)*((b-a)%mod)%mod;
}
int main()
{
ll n, m;
cin>>n>>m;
for(ll i = ; i*i<=n; i++) {
ll tmp = n/i;
v.pb(mk(i, tmp));
if(tmp != i) {
v.pb(mk(tmp, i));
}
}
v.pb(mk(, ));
sort(v.begin(), v.end());
ll ans = (n%mod)*(m%mod)%mod;
int i;
for(i = ; i<v.size()&&m>=v[i].fi; i++) {
ans = (ans- getsum(v[i-].fi, v[i].fi)%mod*(v[i].se%mod)%mod+mod)%mod;
}
if(m<n)
ans = (ans - getsum(v[i-].fi, m)%mod*(v[i].se%mod)%mod+mod)%mod;
cout<<ans<<endl;
return ;
}

codeforces 616E. Sum of Remainders 数学的更多相关文章

  1. Codeforces 616E - Sum of Remainders

    616E Sum of Remainders Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + - + n mod m. As ...

  2. codeforces 616E Sum of Remainders (数论,找规律)

    E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

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

  4. Sum of Remainders(数学题)

    F - Sum of Remainders Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  5. Codeforces 85D Sum of Medians(线段树)

    题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...

  6. Educational Codeforces Round 5 E. Sum of Remainders (思维题)

    题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...

  7. Codeforces 616 E Sum of Remainders

    Discription Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the resu ...

  8. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

  9. Codeforces 789A Anastasia and pebbles(数学,思维题)

    A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...

随机推荐

  1. 值得赞扬的尝试与进步——CSDN开源夏令营第一印象

    注:写这篇文章时我并未參加CSDN开源夏令营,也不确定是否会參加以及是否能參加上. 欣闻CSDN举办了"CSDN开源夏令营"活动.第一感觉是CSDN作为活动的组织者是很值得称赞的. ...

  2. Swift学习之十四:闭包(Closures)

    * 闭包(Closures) * 闭包是自包含的功能代码块,可以在代码中使用或者用来作为参数传值. * 在Swift中的闭包与C.OC中的blocks和其它编程语言(如Python)中的lambdas ...

  3. 游戏开场镜头拉近(Unity3D开发之四)

    猴子原创,欢迎转载.转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢! 原文地址: http://www.cocos2dev.com/? p=553 今天看了个Demo.发现 ...

  4. SMTP协议分析

    SMTP协议分析 第1章.     SMTP概述 1.1.  SMTP在邮件通信中的位置 SMTP,即简单邮件传送协议,所相应RFC文档为RFC821.同http等多数应用层协议一样,它工作在C/S模 ...

  5. 队列的实现 -- 数据结构与算法的javascript描述 第五章

    队列也是列表的一种,有不同于列表的规则. 先进先出 入队方法 出队方法 可以找到队首 可以找到队尾 可以查看队列有多长 可以查看队列是否为空 这是一个基本的需求,围绕他来实现,当然我们可以自己扩展列表 ...

  6. 关于ajax的那些事

    什么是ajax AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. Ajax包含下列技术:基于 ...

  7. 交换机access和trunk的一些小结(转)

     以太网端口有 3种链路类型:access.trunk.hybird Access类型端口只能属于1个VLAN 般用于连接计算机 端口: Trunk类型端口可以允许多个VLAN通过,可以接收和发送多个 ...

  8. 使用VisualStudio发布ASP.NET网站

    1.右击网站点击“发布网站” 2.选择或导入发布配置文件.→新建配置文件. 3.输入名称test.→点击确定. 4.发布方法选择文件系统. 5.选择目标位置.→点击下一步 6.文件发布选项选择三个选项 ...

  9. iReport 4.1 报表制作,子报表,实例解析

    开发使用步骤(iReport 4.1.1) (个人总结,如有问题请留言,另外知道table控件用法的给我留言或者发邮件谢谢.Email:jiazx0107@163.com) 目录 1.      开发 ...

  10. 一篇入门的php Class 文章

    刚在大略浏览了一下首页更新的那篇有关Class的文章(指PHPE的那篇 http://www.phpe.net/articles/389.shtml ),很不错,建议看看.  对类的摸索--俺用了半年 ...