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 ...
随机推荐
- python第三天---collections类
collection系列 1.计数器(counter) Counter是对字典类型的补充,用于追踪值的出现次数. 我们从中挑选一些相对常用的方法来举例: 在上面的例子我们可以看出,counter方法返 ...
- 链表-Add Two Numbers
第一版代码(很挫很罗嗦,不过是第一次做,记录一下成长的脚步!继续努力!) /*struct ListNode { int val; struct ListNode *next; };*/ typede ...
- python 类型转换函数
python提供了一些可将某个值从一种类型转换为另一种类型的内置函数. 1. int函数可以把任何可以转换为整型的值转换为整型.int可以将浮点数转换为整数,但不会做四舍五入操作,而是直接丢弃小数部分 ...
- HDU Exponentiation 1063 Java大数题解
Exponentiation Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- PowerBuilder预防数据库死锁相关处理
实际业务中碰到了PB开发的业务系统造成的数据死锁情况,整理了一些PB关于数据库死锁的一些处理. PB死锁相关 1. 即时的commit和rollback 不同数据库的锁机制各不相同,但对应用程序来说, ...
- Linux分区方案
创建三个分区 1./boot 启动分区 存放内核和启动程序 空间分配:100M 类型:ext4 2./swap 交换分区 虚 ...
- 【转】CoreData以及MagicalRecord (一)
先粗略的了解下CoreData中的一些核心概念 1. CoreData 的核心概念 先上两幅关键的概念图 (1)NSManagedObjectModel 托管对象模型(MOM)是描述应用程序的数据模型 ...
- android EncodingUtils
EncodingUtils 报错Cannot Resolve Symbol EncodingUtils 提示是:错误:程序包org.apache.http.util不存在 错误:找不到符号 符号 ...
- [MAC Eclipse] Eclipse for MAC 中文乱码的解决办法
笔者将在windows下的eclipse写的代码拷贝到MAC下,发现中文会出现乱码. 最初笔者遇到这个问题的时候,在网络上寻找了解决办法,出来的第一个网页(http://blog.csdn.net/w ...
- 框架开发(三)---smarty整合
一 smarty 是什么 Smarty是一个PHP的模板引擎.更明确来说,它可以帮助开发者更好地 分离程序逻辑和页面显示.最好的例子,是当程序员和模板设计师是不同的两个角色的情况,而且 大部分时候都不 ...