【题目分析】

卷积很好玩啊。

【代码】

#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. 《JavaScript高级程序设计》读书笔记 ---变量

    ECMAScript 的变量是松散类型的,所谓松散类型就是可以用来保存任何类型的数据.换句话说,每个变量仅仅是一个用于保存值的占位符而已.定义变量时要使用var 操作符(注意var 是一个关键字),后 ...

  2. sql 语句操作

    插入:insert into table1(field1,field2) values(value1,value2) db.execSQL(sql) db.execSQL(sql, bindArgs) ...

  3. php-fpm配置优化

    PHP配置文件php-fpm的优化 2013/06/28 php, php-fpm 应用加速与性能调优 评论 6,029   本文所涉及的配置文件名为PHP-fpm.conf,里面比较重要的配置项有如 ...

  4. Sasha and Array

    Sasha and Array time limit per test 5 seconds memory limit per test 256 megabytes input standard inp ...

  5. Android------三种监听OnTouchListener、OnLongClickListener同时实现即其中返回值true或者false的含义

    引自:http://5200415.blog.51cto.com/3851969/1003113 android应用中常用的监听OnTouchListener.OnClickListener.OnLo ...

  6. [转] Linux下移动virtualbox虚拟硬盘丢失eth0

    1.遇到什么的问题(What)      在新的virtualbox虚拟机上挂上曾使用过的虚拟硬盘,在启动的时候,发现找不到网卡eth0, 在输入ifconfig –a的时候,也没有任何Ethnet的 ...

  7. 通过ant调用shell脚本执行adb命令

    在Hudson或者Jenkins中利用ant的exec 来调用shell命令,通过shell脚本来执行adb shell命令,可以正常执行,不会出现在ant中直接调用adb shell出现的假死情况. ...

  8. void (*isr_handle_array[50])(void);求解这个申明怎么理解 啊??

    这是函数指针数组.一层一层向里面剥就好啦. 是一个指向 返回值为void 参数也是void的指针数组.先看里面[50]知道是个数组,再向外看是一个函数指针,合起来就是函数指针数组.我写个源码,你就明白 ...

  9. java中“==”和equal区别

    8个月以后就要正式找工作啦,我觉得现在是时候花时间好好深入研究一下以前比较混肴的知识.这就当作是自我成长的第一步! 对于String中的“equal方法”和“==”一直有点混肴,今天重新看了一下他们两 ...

  10. Button MouseEvent颜色变化

    public partial class Form1 : Form { public Form1() { InitializeComponent(); this.button1.Enter += bu ...