【题目分析】

卷积很好玩啊。

【代码】

#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. ubuntu apache2 流量限制模块

    mod-bw is an Apache 2 module provided to solve the problem of limiting users’ and virtual hosts’ ban ...

  2. mysql笔记4之数据操作

    1修改数据 插入:insert into stu(id,name,age,addr) values(2,"李四",44,"重庆"); 2修改某一列 updata ...

  3. 一个appium 博客

    http://www.cnblogs.com/tobecrazy/category/699177.html appium Java控制Appium server start/stop 摘要: 相信很多 ...

  4. Html基础详解之(CSS)

    css选择器 CSS选择器用于选择你想要的元素的样式的模式. “CSS”列表示在CSS版本的属性定义(CSS1,CSS2,CSS3). CSS id和class选择器 <!DOCTYPE htm ...

  5. ssh-copy-id

    建立无密码登录是经现root成功普通用户失败, chmod 0600 authorized_keys setenforce 0 ssh-copy-id  server2 ssh-add   ~/.ss ...

  6. CSS中关于margin的理解误区

    思考一 在以前,我对于margin的理解是这样的,此处用margin-top举例:指的是离相邻元素之间的距离. 但是实际是:相对于自身原来的位置偏移. 举个例子: <!DOCTYPE HTML ...

  7. 两列布局,读《css那些事儿》

    两列布局: 1.两列定宽: 要点:float.width固定. :after清除浮动. 前提:两列的盒模型宽度相加不能大于父元素的宽度,否则会出现错位现象. <!DOCTYPE html> ...

  8. Android学习笔记之Service

    与服务通信 用bindservice 而startservice并无通信条件. service 为android为系统服务,所以程序员无法new出来,只能建立服务,共其他组件使用. package c ...

  9. CodeForces 510E Fox And Dinner

    网络流. 原点到偶数连边,容量为2, 奇数到汇点连边,容量为2, 偶数到与之能凑成素数的奇数连边,容量为1 如果奇数个数不等于偶数个数,输出不可能 如果原点到偶数的边不满流,输出不可能 剩下的情况有解 ...

  10. iOS中利用UISearchBar实现搜索

    先把源码贴出来 https://github.com/losedMemory/ZSSearchBar   这是我在github上写的一个Demo,大家可以看看 在大多数app中都会用到搜索功能,那么搜 ...