Description:

\(t\)组询问,求第\(k\)个大于\(x\)且与\(p\)互质的数

Hint:

\(x,k,p<=1e6,t<=30000\)

Solution:

推出式子后,由于要求第k大,二分答案就好了

#include<bits/stdc++.h>
using namespace std;
const int mxn=1e6+5;
int tot,vis[mxn],mu[mxn],sum[mxn],p[mxn];void sieve(int lim)
{mu[1]=1;for(int i=2;i<=lim;++i) {if(!vis[i]) mu[i]=-1,p[++tot]=i;for(int j=1;j<=tot&&p[j]*i<=lim;++j) {vis[p[j]*i]=1;if(i%p[j]==0) {mu[p[j]*i]=0;break;}mu[p[j]*i]=-mu[i];}}for(int i=1;i<=lim;++i) sum[i]=sum[i-1]+mu[i];
}int check(int x,int p)
{int ans=0;for(int i=1;i<=sqrt(p);++i) if(p%i==0) {ans+=mu[i]*(x/i);if(i*i!=p) ans+=mu[p/i]*(x/(p/i)); //这里很重要,直接将O(n)的check优化到了O(√n)}return ans;
}int main()
{int t,x,p,k;scanf("%d",&t); sieve(1000000);while(t--) {scanf("%d%d%d",&x,&p,&k);int l=x+k-1,r=9e6+5;while(l<r) {int mid=(l+r)>>1;if(check(mid,p)-check(x,p)>=k) r=mid;else l=mid+1;}printf("%d\n",r);}return 0;
}

转载于:https://www.cnblogs.com/list1/p/10372063.html

[CF920G]List Of Integers相关推荐

  1. 莫比乌斯反演习题总结

    一:常用卷积 \[1 * \mu = \epsilon\] \[Id * \mu = \varphi\] \[1 * \varphi = Id \] 最后一个是欧拉反演. 根据这些卷积之间的相互转化, ...

  2. pandas将dataframe原有的数据列名称转化为整数数值列名称(convert dataframe column labelsl into integers)

    pandas将dataframe原有的数据列名称转化为整数数值列名称(convert dataframe column labelsl into integers) 目录 pandas将datafra ...

  3. [LeetCode] Sum of Two Integers 两数之和

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  4. “TypeError: list indices must be integers or slices, not str”有关报错解决方案

    "TypeError: list indices must be integers or slices, not str"有关报错解决方案 参考文章: (1)"TypeE ...

  5. python3 错误string indices must be integers 的解决方法

    这个错误意思是字符串的下标一定要是整数 出这种错误有多种可能,最形象直接的就是: a = '[abc]' print(a['0']) 有点pyhton基础的都知道下标怎么能是字符串'0',必须是整数0 ...

  6. list indices must be integers or slices, not tuple

    11年it研发经验,从一个会计转行为算法工程师,学过C#,c++,java,android,php,go,js,python,CNN神经网络,四千多篇博文,三千多篇原创,只为与你分享,共同成长,一起进 ...

  7. leetcode 371. Sum of Two Integers

    Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...

  8. MATLAB报错“Integers can only be raised to positive integral powers.“

    报错代码是下面这样的: I=imread('pout.jpg'); if size(I,3)>1  %判断如果是彩色图像,转换为灰度图     I=rgb2gray(I); end Gamma_ ...

  9. Divide Two Integers

    Divide two integers without using multiplication, division and mod operator. 思路:不能使用乘法除法以及取模运算来计算两个数 ...

  10. leetcode之Divide Two Integers

    题目:Divide Two Integers Divide two integers without using multiplication, division and mod operator. ...

最新文章

  1. 零点起飞学mysql视频_零点起飞学MySQL
  2. 工作中搜索页面搜索记录功能的封装(存储到本地)
  3. JDK14的新特性:JFR,JMC和JFR事件流
  4. java 循环标记_深入浅析Java 循环中标签的作用
  5. c 富文本html编辑器,富文本HTML编辑器UEditor
  6. Golang的GC和内存逃逸
  7. MITRE 发布防御知识库 Shield
  8. c语言源程序的基础单位,c源程序的基本单位是什么
  9. 磁带机故障灯解决方法
  10. html代码 通用代码,html5可以通用的几段代码 | 睿客网
  11. boos里的AHCI RAID_如何用Intel主板集成的RAID控制器(Intel RST)实现硬盘提速与硬盘数据恢复...
  12. ktv无线服务器,KTV无线网络覆盖方案-无死角WIFI信号全覆盖方法
  13. 计算机相关美文摘抄,写景美文摘抄
  14. 论成长型思维的重要性
  15. EtherCAT运动控制器在数控加工手轮随动中的应用之C++
  16. php vip卡,vip.php
  17. P02014026黄一洋————信息论问题回答
  18. Hive面试题考点-整理
  19. Druid后台监控与过滤器
  20. GPU显卡环境配置安装

热门文章

  1. 第一次使用博客,略激动。
  2. 前端必知必会HTTP请求系列(一)了解Web及网络基础
  3. iOS - OC NSTimeZone 时区
  4. Extjs的radio单选框的使用
  5. Windows CE的存储与地址映射技术学习
  6. python中的append()有什么功能_关于列表:在Python中,“。append()”和“+ = []”之间有什么区别?...
  7. 用python写个小游戏难吗_小伙用Python制做一个小游戏,结果6秒就结束,怎么难玩?...
  8. Mac vscode花屏问题解决
  9. html模板引擎 字符串长度,javascript轻量级模板引擎juicer使用指南
  10. 使用java获取网络响应内容--Get请求方式