【题目链接】 http://www.lydsy.com/JudgeOnline/problem.php?id=1257

【题目大意】

  给出正整数n和k,计算j(n,k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值

【题解】

  我们发现k%i=k-[k/i]*i,j(n,k)=n*k-∑[k/i]*i,我们知道[k/i]的取值不超过k^(1/2)个,
  并且在分布上是连续的,所以我们可以分段求和,对于段开头l,其段结尾r=k/[k/l]。

【代码】

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
LL n,k;
int main(){
while(~scanf("%lld%lld",&n,&k)){
LL r,ans=n*k;
if(n>k)n=k;
for(LL l=1;l<=n;l=r+1){
LL u=k/l;
r=min(k/u,n);
ans-=(l+r)*(r-l+1)*u/2;
}printf("%lld\n",ans);
}return 0;
}

BZOJ 1257 [CQOI2007]余数之和sum(分块)的更多相关文章

  1. Bzoj 1257 [CQOI2007]余数之和 (整除分块)

    Bzoj 1257 [CQOI2007]余数之和 (整除分块) 题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1257 一道简单题. 题目 ...

  2. BZOJ 1257: [CQOI2007]余数之和sum

    1257: [CQOI2007]余数之和sum Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 3769  Solved: 1734[Submit][St ...

  3. bzoj 1257: [CQOI2007]余数之和sum 数学 && 枚举

    1257: [CQOI2007]余数之和sum Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 1779  Solved: 823[Submit][Sta ...

  4. BZOJ 1257: [CQOI2007]余数之和sum( 数论 )

    n >= k 部分对答案的贡献为 k * (n - k) n < k 部分贡献为 ∑ (k - ⌊k / i⌋ * i)  = ∑  , ⌊k / i⌋ 相等的数是连续的一段, 此时这段连 ...

  5. BZOJ 1257: [CQOI2007]余数之和sum【神奇的做法,思维题】

    1257: [CQOI2007]余数之和sum Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 4474  Solved: 2083[Submit][St ...

  6. [BZOJ 1257] [CQOI2007] 余数之和sum 【数学】

    题目链接:BZOJ - 1257 题目分析 首先, a % b = a - (a/b) * b,那么答案就是 sigma(k % i) = n * k - sigma(k / i) * i     ( ...

  7. bzoj 1257: [CQOI2007]余数之和 (数学+分块)

    Description 给出正整数n和k,计算j(n, k)=k mod 1 + k mod 2 + k mod 3 + … + k mod n的值 其中k mod i表示k除以i的余数. 例如j(5 ...

  8. bzoj 1257 [CQOI2007]余数之和——数论分块

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1257 \( n\%i = n - \left \lfloor n/i \right \rfl ...

  9. BZOJ 1257 [CQOI2007]余数之和sum ——Dirichlet积

    [题目分析] 卷积很好玩啊. [代码] #include <cstdio> #include <cstring> #include <cmath> #include ...

随机推荐

  1. DotNet 学习笔记 Servers

    Servers ASP.NET Core ships with two different HTTP servers: •Microsoft.AspNetCore.Server.Kestrel (AK ...

  2. Java线程总结(一)

    首先,先贴上一个简单的线程实例: public class MyThread extends Thread{ @Override public void run(){ try { for (int i ...

  3. bootstrap-table设置某列序号自增

    col = [{ field: 'SerialNumber', title: '序号', formatter: function (value, row, index) { return index+ ...

  4. Python模块学习 - Argparse

    argparse模块 在Python中,argparse模块是标准库中用来解析命令行参数的模块,用来替代已经过时的optparse模块.argparse模块能够根据程序中的定义从sys.argv中解析 ...

  5. 【jzoj6.24模拟B】

    这场真是无聊,搬远古原题…… xjb做了做,(居然没AK真是身败名裂) A.教主的花园 答案明显具有可二分性,二分答案判定下就行. #include<bits/stdc++.h> #def ...

  6. yum安装的Apache的各种配置文件的位置

    //配置文件 /etc/httpd/conf /etc/httpd/conf.d /etc/httpd/conf.d/README /etc/httpd/conf.d/proxy_ajp.conf / ...

  7. HDU 2993 MAX Average Problem(斜率DP经典+输入输出外挂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2993 题目大意:给出n,k,给定一个长度为n的序列,从其中找连续的长度大于等于k的子序列使得子序列中的 ...

  8. P2725 邮票 Stamps(完全背包+限制填充数)

    题目链接:https://www.luogu.org/problem/show?pid=2725 题目大意:给一组 N 枚邮票的面值集合(如,{1 分,3 分})和一个上限 K —— 表示信封上能够贴 ...

  9. Sql 中取小数点后面两位小数

    ,),round(UnTaxAmount,))as UnTaxAmount from View_SaleVoice ,)) as UnTaxAmount from View_SaleVoice

  10. AC日记——背单词 洛谷 P2353

    背单词 思路: KMP+统计前缀和优化: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 ], ...