莫比乌斯函数/容斥原理
PoPoQQQ讲义引入例题= =
比较水……就是莫比乌斯函数的简单应用,也可理解为乱容斥一下……
二分答案——>求1~x有多少个无平方因子的数Q(x)。
引用一下PoPoQQQ的题解:
•根据容斥原理可知 对于sqrt(x)以内所有的质数 有
• x以内的无平方因子数
•=0个质数乘积的平方的倍数的数的数量(1的倍数)
•-每个质数的平方的倍数的数的数量(9的倍数,25的倍数,...)
•+每2个质数乘积的平方的倍数的数的数量(36的倍数,100的倍数,...)-...
•容易发现每个乘积a前面的符号恰好是aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFMAAAAyCAIAAACveHCoAAACFElEQVRoge3a0bmDIAwG0MzFQMzDNCzDMN6HVkWU5A9EvP0wr9qQIwiKpWXWoKcLeCxe+XzxyueLVz5fPCdPwbmQnsvyiDwFR0Q+2mSLnoj0/OFyW/UhqU4/Vn4LO0+twI+UR093uRvyD5N/+uRG97KsdqzjB8m/boPJ3KydMfJPX9wP3+hAUyr5mraWt3L86x4Bz2qQ7iuN/An4+uMiQfRVGkpXyDvh2sntdMum4MjHLV81HdggLu+Fa7q8MlGl4Jzjq8gL4emwXBJIcLzLmelwz8ZdR6xNVC7BK8f36w92OT83YyasUVDeCAc76XR67WTsFt7l3HmYvBWuk4trMThtZ3KmVUjeDMdqKM6V4VIu6Hoj8ma4Ri4PZBhuJm+HK0a7DFesEkbyHjgsF1d9bNbSnCvKu+BowdLDR5YGeC6wWdX64OoV+DJL9ORCwJ/+TZ5kuNGad8R2OPrais6VzPRS9ORCKlb6FELdBD498fL8Tal8VSIXUtnIyb0gc9exoeMrypY4S5KCg3Lxw4OVH+B5rDkP3V7DQfQyU1F6luPq6l5man9LXS/5oagiHbRgg/skl3fP+ZgAMtiZyMZad/zUbpTtFvHv7EDa7xEPsffvOt8zOjV1tYTuM8uVHH81uLc2XWg/LF7IGzaQNNH46dM86VnetGWoDFO92VfkIR/Alkn/OfAv4pXPF698vnjl88W88j+EB2q8FnJm/AAAAABJRU5ErkJggg==" alt="" width="40" height="25" />(例如aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJ0AAAAxCAIAAABPmjwUAAACk0lEQVR4nO2byQGFIAxEqcuCrMdqbMZi/Ad3fjYBUcfMUWV9JBiMYXQhKtzdAdclcq6Ycq6Ycq6Ycq6Ycq6Ycq6Ycq6Yuo1r34a2/7s6dE04iHiGLgmmeSKSB3oH174NITTdQF0mFY9uehIRbjwHr+HKMKVQ7cfIrQIktn0bQtMNB5f1Dq4c1LFvyct7t0w7ZDC0s7YV/QKuPAVpw1zJStzR0G7L+fFcJ6okHEtBtigk2ddwneGk9HIeI78iMup+ql7CdTG5pE7qm2hW9Y9UZa7yXsfdX6+mY1VKwoGtyzUTa8LeOvatZWhZTTxRVbnWxjqVNBVb4wIQsDW5rnPHNKVgPdXD+NRFw7W1Yn/ylCqvl4pc07CejrDZs0R5Zs3NONejErHaDYmt0DS3G1cIT1yNayLW7Pk+mi8/SPm88WKV9wG1uKZiLWFHO7R8Hc41loVrMtYi/tHiy2/lWl51uKZjLbPvGUIl5xpL56phlYLH9PcmqhbL/qq04+/Di8xYyfsFviRavtl4nBNL46od5Sj3ixisevRfxi08R9dzFTdIKlGlb7kINrWLUw1iabQD4su5HuLHXRuLBcWGElMdLXO+PMFnRFidKwhWkatxyxG5qhmC8XZFTqzyGe1Yx6GGOZNL6uK+ARSsQsJeRIRHK3G1JMhZIhn1+yj3NnPuTPn1EQ5vRtvsRlPFjpnnOnRNMRO4MlcFMA/GJtGbsVxLYh0z8tYUQeatmSS/eXBcy+fmnvhOfrLOL1LVXihprrNvK21ehReLIQJClZr2RXHNyzQzdKhExd+Fahr5P9frD2+y2X6XqTHyo7hqB8KFlP634yf+k8wVZ68oMf5X5f+rY8q5Ysq5Ysq5Ysq5Ysq5Ysq5YuoHoQGeiXDzRugAAAAASUVORK5CYII=" alt="" width="74" height="23" />故9对答案的贡献为负;aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAAAxCAIAAACdyjZMAAACc0lEQVR4nO2b2wGDIAxFmcuBnMdpXMZh7If1UUrIDQUSbe5nBYF7EMKjYXWpKmhX4N/lAJTlAJTlAJTlAJTlAJTlAJTlAJSlBmAewzgLEp/asonyK2iZhrOyGWkAmMcQwjAtfMp3K67GR6+xRuGjq1gEgJt/NiXTCFMQ5jGEYVqyveZLXQHA7p9t4L01xeAtqPNs6gcANkri/jWDIQaCJvQCsNnP9/6z6tA49ZnLDAJzAN6fJFubMvslJfSRMQD7iMhVptx+QSFd1AjA8VrCn/Tz41euLoKZK5fdAoE2AH70n+nVl+CtzEK0oB5qAqCv//GCBrD1yKJPoAWAo3nEKxn/mZp8LF6i5BcW2ZeIppCvAjGBbBsAKPMfHtfPdMkmYuOTZBK5G4BC/9FOyRvMEILT9FF1AIX+w5YA6YCP4Od5vJpqAyj1vyYA4Gt6LIBi/2EA0FDFDvFPBVDuPz4qIyEk26qHAuD8z3kHR4ZIjdklhSQOvU8UBPuffA5HhkCV9ySkCY8MQ7mxgXku6JQc6T0BECdpR6EVAWQH8et2wf54HqmVAL4XnVuLIXOEuv/1ACRuI1x+H+e408X2r0Jb9vKo6TzXHEP+VwPwtSMWw4hH0mTbZfvECQbYeRcNr7tSQwOlHADklF+yRQDHhrmtuVxlRYU0EN1haXtoAMs0VOtO7Q8MbR1JCkQCqOn/ih/Kl8naobxAFID6t202k1oguLH9FAAu5C5UkztUm/33dH9NA4CP0QtUmcHN3V9TANovKCtBuL/565oCwG4J1NGv18utX09HRX0BBpYz/yH/h4yyHICyHICyHICyHICyHICyHICyXlapXv3d1AXDAAAAAElFTkSuQmCC" alt="" width="55" height="21" />,故36对答案的贡献为正)
•x以内i^2的倍数有aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAABbCAIAAACnLa/SAAAB+klEQVR4nO2ayZXDIAxA1UD6SA10kSbURzqggEwbOqUTimEOjhO8jDMBISm2/tF+RvqPHQx5L4B2Amy4iT3cxB67NSEECDHp5PKe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x0iFKwgovbIRjoEKVgBb/GQzDQIbop3CVnuyTvFIKBNlEJVnQ2GQQDHaIRrOxsTQjWM/4T4htFIVjh2dAQrBWYy+25vxJwL+SClV5tAMG6pof12h6In7v47pgQrGsgGI/yu89CsAaQ/24ZBGPB3CLfAgjWCPt9NNITgvdvXwjGgblFvgkQrA2EpkAw9lEhELfItwGCNYFUFAjGQfqDqhogWAuIPYFgrQPBGuAcBPTBcvTz3BCsPtppCV1UNFv6eW4IVp15fGQlyV6r/VQ0W/p5bghWG+niP8LvTt4XCAaAI4Stg4rpp7gXCAbaBIIBAHJAMAAcgWAAOALBAHAEggHgCAQDwJH/gPIgepFUzWYAAAAASUVORK5CYII=" alt="" width="136" height="53" />
/**************************************************************
Problem: 2440
User: Tunix
Language: C++
Result: Accepted
Time:2360 ms
Memory:10060 kb
****************************************************************/
//BZOJ 2440
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<='') {v=v*+ch-''; ch=getchar();}
return v*=sign;
}
/*******************tamplate********************/
const int N=1e6+;
typedef long long LL;
int mu[N],prime[N];
bool check[N];
void getmu(int n){
int tot=;
mu[]=;
for(int i=;i<n;++i){
if (!check[i]){
prime[tot++]=i;
mu[i]=-;
}
rep(j,tot){
if (i*prime[j]>n) break;
check[i*prime[j]]=;
if (i%prime[j]) mu[i*prime[j]]=-mu[i];
else{
mu[i*prime[j]]=;
break;
}
}
}
}
int judge(int x){
int ans=;
for(int i=;i*i<=x;i++)
ans+=mu[i]*((LL)x/(i*i));
return ans;
}
int main(){
int T=getint(),n;
getmu(N-);
while(T--){
n=getint();
int l=,r=n*,mid=,now=;
while(l<r){
mid=l+(r-l>>);
now=judge(mid);
if (now<n) l=mid+;
else r=mid;
}
printf("%d\n",l);
}
return ;
}
- BZOJ 2440 [中山市选2011]完全平方数 | 莫比乌斯函数
BZOJ 2440 [中山市选2011]完全平方数 | 莫比乌斯函数 题面 找出第k个不是平方数的倍数的数(1不是平方数, \(k \le 10^9\)). 题解 首先二分答案,问题就转化成了求\([ ...
- BZOJ 2440 [中山市选2011]完全平方数 (二分 + 莫比乌斯函数)
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 4805 Solved: 2325[Submit][Sta ...
- BZOJ 2440: [中山市选2011]完全平方数 [容斥原理 莫比乌斯函数]
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3028 Solved: 1460[Submit][Sta ...
- BZOJ 2440: [中山市选2011]完全平方数( 二分答案 + 容斥原理 + 莫比乌斯函数 )
先二分答案m,<=m的有m-∑(m/pi*pi)+∑(m/pi*pi*pj*pj)-……个符合题意的(容斥原理), 容斥系数就是莫比乌斯函数μ(预处理)... ----------------- ...
- Bzoj 2440: [中山市选2011]完全平方数(莫比乌斯函数+容斥原理+二分答案)
2440: [中山市选2011]完全平方数 Time Limit: 10 Sec Memory Limit: 128 MB Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平 ...
- [BZOJ 2440] [中山市选2011] 完全平方数 【二分 + 莫比乌斯函数】
题目链接:BZOJ - 2440 题目分析 首先,通过打表之类的方法可以知道,答案不会超过 2 * k . 那么我们使用二分,对于一个二分的值 x ,求出 [1, x] 之间的可以送出的数有多少个. ...
- BZOJ 2440 [中山市选2011]完全平方数 二分+容斥
直接筛$\mu$?+爆算?再不行筛素数再筛个数?但不就是$\mu^2$的前缀和吗? 放...怕不是数论白学了$qwq$ 思路:二分+容斥 提交:两次(康了题解) 题解: 首先答案满足二分性质(递增), ...
- bzoj 2440: [中山市选2011]完全平方数
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...
- BZOJ.2440.[中山市选2011]完全平方数(莫比乌斯函数 二分)
题目链接 总感觉博客园的\(Markdown\)很..\(gouzhi\),可以看这的. 题意即求第\(k\)个无平方因子数. 无平方因子数(Square-Free Number),即分解之后所有质因 ...
- BZOJ 2440 [中山市选2011]完全平方数 ——莫比乌斯函数
$\sum_{i=1}^n[i==d^2*p]$ 其中p无平方因子$=\sum_{d^2\mid n,d>=2}\sum_{i=1}^{\lfloor {n/d^2} \rfloor} \lef ...
随机推荐
- Cocos2d-JS中的精灵菜单和图片菜单
精灵菜单的菜单项类是cc.MenuItemSprite,图片菜单的菜单项类是cc.MenuItemImage.由于cc.MenuItemImage继承于cc.MenuItemSprite,所以图片菜单 ...
- "Could not load file or assembly 'DTcms.Web.UI' or one of its dependencies. 拒绝访问。" 的解决办法
出现的问题提示如下:
- UI1_UIView层操作
// // ViewController.m // UI1_UIView层操作 // // Created by zhangxueming on 15/7/1. // Copyright (c) 20 ...
- HDU1022 Train Problem I 栈的模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 栈的模拟,题目大意是已知元素次序, 判断出栈次序是否合理. 需要考虑到各种情况, 分类处理. 常 ...
- 单元测试+修改BUG
程序源代码: #include<iostream> using namespace std; int Largest(int list[], int length) { int i, ma ...
- tomcat中的get、post区别
最近做一个项目,前台传到后台的数据是乱码.看着代码应该是正确的,但是就是有问题,然后请教了旁边的老司机才找到问题是什么.话不多说,下面是模拟情景的代码,其实也很简单,前台一个form表单,post ...
- jexus 配置 学习
http://www.linuxdot.net/ 1.禁止或允许某IP或IP段访问网站 A.只允许某些IP地址访问网站(白名单功能) 默认情况下,允许所有IP地址访问.如果手工设置IP地址白名单, 那 ...
- sql server 查询多个不关联表且对结果编号
1.除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图.内联函数.派生表.子查询和公用表表达式中无效. 解决方法:top 100 percent * 2.如何对查询结果编 ...
- perl编程中的map函数示例
转自:http://www.jbxue.com/article/14854.html 发布:脚本学堂/Perl 编辑:JB01 2013-12-20 10:20:01 [大 中 小] 本文介绍 ...
- php 图形验证码的3种方法
生成图形验证码需要使用php GD库来生成,如果你没开户GD库我们需要在php.ini文件找到extension=php_gd2.dll 去掉前面的;就行了,然后重启apache 或iis环境即可 检 ...