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 ...
随机推荐
- 愤怒的DZY(二分)
愤怒的DZY[问题描述]“愤怒的小鸟”如今已经是家喻户晓的游戏了,机智的WJC最近发明了一个类似的新游戏:“愤怒的DZY”.游戏是这样的:玩家有K个DZY,和N个位于不同的整数位置:X1,X2,…,X ...
- SRM 584 div2
早早地水完了三道题,pt1000用的是dfs,开始做的时候误认为复杂度最多就O(2^25),结果被一组O(2*3^16)的数据接近1e8给cha了.继续努力. pt250:求两个串的前缀组成的不同串数 ...
- 常用的连接字符串(vs中连接sqlserver)方便随时查看
Sql Server身份验证有两种,一种是Windows身份验证,还有一种是Sql Server 身份验证 Windows身份验证连接字符串: string connectionString = &q ...
- HTML系列(四):编辑图像
一.图像的基本概念 1.矢量图:文件占用空间小,放大后图像不会失真,和分辨率无关.适用于图形设计.文字设计.标志设计.版式设计等. 2.位图:由像素点组成,文件较大,放大和缩小图像会失真. 3.有损压 ...
- MailBee的简单使用
保存为Eml文件方法:MailMessage.SaveMessage() 读取文件方法(不知道是不是我用的问题,没找到直接读取Eml文件的方法): MsgConvert conv = new MsgC ...
- Javascript 获取窗口的大小和位置
在Javascript中可以使用OuterWidth,OuterHeight 获取浏览器的大小.用 innerWidth,innerHeight 来获取窗口的大小(除去浏览器边框部分).对于IE6 及 ...
- JavaSE思维导图(五)
- Android EditeText常用功能盘点
这篇集合了项目里经常用到的EditText的需求,以前单个问题总结过,现在放在一起以备后患啊,主要包含以下方面: 1. 判断输入字符长度 2. 键盘的显示与隐藏 3. 对输入内容的限制,列举几种常见的 ...
- ORACLE查看当前连接用户的权限信息或者角色信息
关于当前用户的相关信息,可以通过如下语句找到: SQL> select * from all_objects where object_name like 'SESSION%'; OWNER O ...
- 使用#define定义字面值和伪函数
#define是C语言提供的宏命令,其主要目的是:在编程时,为程序员提供一定方便,并能在一定程度上提高程序的执行效率.#define将一个标示符定义为一个字符串,该标示符被称为宏,被定义的字符串称为字 ...