【题目分析】

卷积很好玩啊。

【代码】

#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积的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. BZOJ 1257 [CQOI2007]余数之和sum(分块)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1257 [题目大意] 给出正整数n和k,计算j(n,k)=k mod 1 + k mod ...

  7. 1257: [CQOI2007]余数之和sum

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

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

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

  9. BZOJ 1257: [CQOI2007]余数之和

    1257: [CQOI2007]余数之和 Time Limit: 5 Sec  Memory Limit: 128 MB Description 给出正整数n和k,计算j(n, k)=k mod 1 ...

随机推荐

  1. synchronized关键字以及实例锁 类锁

    Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问同一个对象object中的这个synchronized(this ...

  2. myEclipse JSP 调用 IDL8.2 配置

    新安装了Envi5.0 IDL8.2,路径改动了,一些配置也要随之改动.现在总结一下,JSP调用IDL的配置. jar包配置,环境变量配置,dll配置,tomcat路径配置,tomcat运行选项配置, ...

  3. Oracle sql优化之分析函数优化标量子查询

    待优化语句如下 select a.code as code, a.m_code as m_code,a.stktype as f_stype,a.e_year as e_year, b.sname a ...

  4. Chapter 1 First Sight——23

    I stared because their faces, so different, so similar, were all devastatingly, inhumanly beautiful. ...

  5. startActivityForResult相关的

    在Fragment里调用startActivityForResult,界面回来后,会先走其宿主Activity的onActivityResult方法,再走Fragment的. 在Fragment里面嵌 ...

  6. YII2 随笔 视图最佳实践

    yii\base\Controller::render(): 渲染一个 视图名 并使用一个 布局 返回到渲染结果. yii\base\Controller::renderPartial(): 渲染一个 ...

  7. 使用curl获取乱码问题

    今天通过curl获取百度地图接口数据,获取到居然是乱码,于是我查看是不是编码问题,发现返回的编码和自己的编码都是utf-8, 继续找原因,发现header报文中  Content-encoding 为 ...

  8. usb调试

    修改文件:/home/mxy/code/v1/kernel-3.10/drivers/power/mediatek/battery_common.c //bool AutoDebug=true;//x ...

  9. C#入门经典(3-窗体应用程序-第二章要点)

    新建一个窗体用用程序,拖一个按钮,加事件和Text属性.打开Form1Designer.cs.

  10. ural1855 Trade Guilds of Erathia

    Trade Guilds of Erathia Time limit: 2.0 secondMemory limit: 64 MB The continent of Antagarich was co ...