codeforces 616E. Sum of Remainders 数学
给两个数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 数学的更多相关文章
- 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 ...
- codeforces 616E Sum of Remainders (数论,找规律)
E. Sum of Remainders time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- Sum of Remainders(数学题)
F - Sum of Remainders Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- Codeforces 85D Sum of Medians(线段树)
题目链接:Codeforces 85D - Sum of Medians 题目大意:N个操作,add x:向集合中加入x:del x:删除集合中的x:sum:将集合排序后,将集合中全部下标i % 5 ...
- Educational Codeforces Round 5 E. Sum of Remainders (思维题)
题目链接:http://codeforces.com/problemset/problem/616/E 题意很简单就不说了. 因为n % x = n - n / x * x 所以答案就等于 n * m ...
- 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 ...
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
- Codeforces 789A Anastasia and pebbles(数学,思维题)
A. Anastasia and pebbles time limit per test:1 second memory limit per test:256 megabytes input:stan ...
随机推荐
- C++ 清空消息队列
在button等被禁用后,可能须要它在禁用期间不去响应不论什么消息. 能够使用以下的语句片段: MSG msg; //消耗掉消息队列中的全部消息 while(::PeekMessage(&ms ...
- nyist 303序号互换(数学推理)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=303 思路: 开始看错题了,以为最多只有两个字母. 字母转数字的表达式很容易看出来是:(2 ...
- git、githup使用
一.git安装.配置 git安装: root@ubuntu~# apt-get install git git配置githup/自己的git服务器端账号, 即在用户的home目录下生成.gitco ...
- 通过 CsvListWriter 读写.csv文件辅助类
package cn.gov.cnis.db; import java.io.File; import java.io.FileReader; import java.io.FileWriter; i ...
- asp.net MVC Razor 语法(3)
编程逻辑:执行基于条件的代码. If 条件 C# 允许您执行基于条件的代码. 如需测试某个条件,您可以使用 if 语句.if 语句会基于您的测试来返回 true 或 false: if 语句启动代码块 ...
- Lambda表达式图解
internal delegate int MyDel(int x); public class Lambda { ; };//匿名方法 ; };//Lambda表达式 ; };//Lambda表达式 ...
- IOS8 不用计算Cell高度的TableView实现方案
这个新特性,意味着View被Autolayout调整frame后,会自动拉伸和收缩SupView. 具体到Cell,要求cell.contentView的四条边都与内部元素有约束关系. 在TableV ...
- IE7.JS解决IE兼容性问题方法
转自:http://code.google.com/p/ie7-js/ 使IE5,IE6兼容到IE7模式(推荐) <!--[if lt IE 7]> <script src=&quo ...
- UVALive 6709 - Mosaic 二维线段树
题目链接 给一个n*n的方格, 每个方格有值. 每次询问, 给出三个数x, y, l, 求出以x, y为中心的边长为l的正方形内的最大值与最小值, 输出(maxx+minn)/2, 并将x, y这个格 ...
- ZOJ 3741 Eternal Reality
Eternal Reality Time Limit: 2 Seconds Memory Limit: 65536 KB In ...