BZOJ 1257 [CQOI2007]余数之和sum ——Dirichlet积
【题目分析】
卷积很好玩啊。

【代码】
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 500005
#define ll long long
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i)
void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("wa.txt","w",stdout);
#endif
}
int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int n,k,r,l;
ll ans=0;
int main()
{
Finout();
n=Getint(); k=Getint();
ans=(ll)n*(ll)k;
// cout<<"ans is "<<ans<<endl;
int now=1; r=min(n,k);
while (r)
{
now=k/r;
// cout<<now<<" "<<n<<" "<<k<<" "<<r<<endl;
l=k/(now+1)+1;
// cout<<"now "<<now<<endl;
// cout<<l<<"---"<<r<<endl;
ans-=((ll)r+(ll)l)*((ll)r-(ll)l+1)/2LL*(ll)now;
// cout<<"ans is "<<ans<<endl;
r=l-1;
// cout<<"r is "<<r<<endl;
}
cout<<ans<<endl;
}
BZOJ 1257 [CQOI2007]余数之和sum ——Dirichlet积的更多相关文章
- BZOJ 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3769 Solved: 1734[Submit][St ...
- bzoj 1257: [CQOI2007]余数之和sum 数学 && 枚举
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 1779 Solved: 823[Submit][Sta ...
- BZOJ 1257: [CQOI2007]余数之和sum( 数论 )
n >= k 部分对答案的贡献为 k * (n - k) n < k 部分贡献为 ∑ (k - ⌊k / i⌋ * i) = ∑ , ⌊k / i⌋ 相等的数是连续的一段, 此时这段连 ...
- BZOJ 1257: [CQOI2007]余数之和sum【神奇的做法,思维题】
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 4474 Solved: 2083[Submit][St ...
- [BZOJ 1257] [CQOI2007] 余数之和sum 【数学】
题目链接:BZOJ - 1257 题目分析 首先, a % b = a - (a/b) * b,那么答案就是 sigma(k % i) = n * k - sigma(k / i) * i ( ...
- BZOJ 1257 [CQOI2007]余数之和sum(分块)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1257 [题目大意] 给出正整数n和k,计算j(n,k)=k mod 1 + k mod ...
- 1257: [CQOI2007]余数之和sum
1257: [CQOI2007]余数之和sum Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 2001 Solved: 928[Submit][Sta ...
- Bzoj 1257 [CQOI2007]余数之和 (整除分块)
Bzoj 1257 [CQOI2007]余数之和 (整除分块) 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1257 一道简单题. 题目 ...
- BZOJ 1257: [CQOI2007]余数之和
1257: [CQOI2007]余数之和 Time Limit: 5 Sec Memory Limit: 128 MB Description 给出正整数n和k,计算j(n, k)=k mod 1 ...
随机推荐
- GenericApp SampleApp SimpleAp的区别
SampleApp3.2 Zigbee2007 协议栈实验例程表演说明C:\Texas Instruments\ZStack-2.0.0-1.2.0\Projects\zstack\Samples\S ...
- StringWriter/PrintWriter在Java输出异常信息中的作用
闲来无事,看看JUnit的源代码.刚刚开始看就发现一段有趣的代码: public String trace() { StringWriter stringWriter = new StringWrit ...
- MongoDB如何设置权限(类似关系型数据库的用户名和密码)
MongoDB 缺省是没有设置鉴权的,业界大部分使用 MongoDB 的项目也没有设置访问权限.这就意味着只要知道 MongoDB 服务器的端口,任何能访问到这台服务器的人都可以查询和操作 Mongo ...
- odd or even?
public boolean isEven(int data){ if((data&1)== 0) return true; return false; } much faster than ...
- C# 经典入门12章-使用泛型-1
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8sAAAK5CAIAAAAHDiuGAAAgAElEQVR4nOyd9V9Uzfv/v3/J0t0N0p
- 转 Linux进程状态分析
众所周知,现在的分时操作系统能够在一个CPU上运行多个程序,让这些程序表面上看起来是在同时运行的.linux就是这样的一个操作系统.在linux系统中,每个被运行的程序实例对应一个或多个进程.l ...
- Android在一个APP中通过包名或类名启动另一个APP
开发有时需要在一个应用中启动另一个应用,比如Launcher加载所有的已安装的程序的列表,当点击图标时可以启动另一个应用.一般我们知道了另一个应用的包名和MainActivity的名字之后便可以直接通 ...
- hrbust 1721 A + B = 0 map的应用
13级春季校赛的热身题,但优化后我的代码也超时了,后来看了看学长的解法,觉得最简单的还是map,再一次感受到了map的强大. 题目描述如下 Description There is an intege ...
- 使用Spring框架的好处(转帖)
http://blog.csdn.net/cynhafa/article/details/6205361 在SSH框假中spring充当了管理容器的角色.我们都知道Hibernate用来做持久层,因为 ...
- iOS 旋屏问题
今天突然想起来,以前的一个问题没有解决,就上网百度了一些方法,看到一篇文章,写的很详细,我就操作试试,结果还真的实现了功能,接下来我将重复他的结合我自己的测试,说一下iOS中的旋屏问题. 1.首先配置 ...