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 ...
随机推荐
- 转:selenium 并行启动多个浏览器
https://github.com/fool2fish/selenium-doc/blob/master/official-site/selenium-grid.md Selenium Grid 快 ...
- 善用log日志
#-*- coding:utf-8 -*- import logging logger = logging.getLogger() #定义一个log日志对象 hdlr = logging.FileHa ...
- Django: 之数据库导入、迁移和联用
Django 数据库导入 从网上下载的一些数据,excel表格,xml文件,txt文件等有时候我们想把它导入数据库,应该如何操作呢? 以下操作符合 Django版本为 1.6 ,兼顾 Django 1 ...
- iptables详解--转
出处:http://yijiu.blog.51cto.com/433846/1356254 iptables详解 基本概念: 1.防火墙工作在主机边缘:对于进出本网络或者本主机的数据报文,根据事先设定 ...
- JavaBean--简介及基本使用
JavaBean本身就是一个类,属于java的面向对象编程 JavaBean是使用java语言开发的一个可重用的组建,在JSP开发中如果要应用JSP提供的JavaBean标签来操作简单的类的话,需要满 ...
- DIV 浮动存不占空间
DIV 浮动存不占空间比如<div style="width:80px; border:1px solid #333"><div style="floa ...
- qemu -hda /dev/sdc -m 1024 -vga std
同事拿了个烂u盘让我给他做个启动盘,用cp *.iso /dev/sdc怎么也启动不了. 改用dd if=copied/20140923/debian-7.6.0-amd64-DVD-1.iso of ...
- 转 SQL 基础--> NEW_VALUE 的使用
--=============================== -- SQL 基础--> NEW_VALUE 的使用 --=============================== 通常 ...
- css设置层级显示
效果: 代码: <li id="tabIdcontent4" class="nomal" tabid="content4" style ...
- map遍历的四种方式
原文 http://blog.csdn.net/dayanxuqun/article/details/26348277 以下是map遍历的四种方式: // 一.推荐只用value的时候用,都懂的... ...