题目链接

给两个数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. CSS实现宽高成比例缩放

    用js实现一个宽度自适应,高度随着宽度变化而变化的矩形,相信大家肯定都会.无非是js获取一下元素宽度,然后再计算出相应比例的高度,然后赋给元素,但如果要求只用CSS实现呢.         html代 ...

  2. 剑指offer 22 栈的压入、弹出序列

    class Solution { public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { bool resu ...

  3. js判断终端是手机还是电脑

    $(function(){ function browserRedirect() { var sUserAgent= navigator.userAgent.toLowerCase(); var bI ...

  4. Review1-11

    泛型 泛型类 Public 类名 class<T>{} 泛型方法 Public static <T> 返回类型 方法名(<T> t){} 泛型类型必须使用引用类型 ...

  5. Matrix(多线程dp)

    Matrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. 【翻译】在Ext JS 5种使用ViewControllers

    原文:Using ViewControllers in Ext JS 5 简单介绍 在Ext JS 5中,在应用程序架构方面提供了一些令人兴奋的改进,如加入了ViewModels.MVVM以及view ...

  7. iOS_词典阵列 按key分组和排序

    // // main.m // SortGroup // // Created by beyond on 14-10-26. // Copyright (c) 2014年 beyond.com All ...

  8. 使用sqlplus批量执行脚本的总结

    当然,我们可以在plsql中执行,但是在实际生产环境中,可能更多的是使用简便的sqlplus.步骤如下: 1.登陆client sqlplus connect <username>/< ...

  9. STL模板_智能指针概念

    一.智能指针1.类类型对象,在其内部封装了一个普通指针.当智能指针对象因离开作用域而被析构时,其析构函数被执行,通过其内部封装的普通指针,销毁该指针的目标对象,避免内存泄露.2.为了表现出和普通指针一 ...

  10. 用C++写一个简单的发布者

    节点是一个可执行程序,它连接到了ROS的网络系统中.我们将会创建一个发布者,也就是说话者节点,它将会持续的广播一个信息. 改变目录到之前所建立的那个包下: cd ~/catkin_ws/src/beg ...