920G - List Of Integers

思路:容斥+二分

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a)) vector<int>p;
ll ans=;
void dfs(int k,int cnt,ll s,ll r){
if(k==p.size()){
if(cnt&)ans-=r/s;
else ans+=r/s;
return ;
}
dfs(k+,cnt,s,r);
dfs(k+,cnt+,s*p[k],r);
}
void init(ll n){
p.clear();
for(ll i=;i*i<=n;i++){
if(n%i==){
p.pb(i);
while(n%i==)n/=i;
}
}
if(n>)p.pb(n);
}
ll count(ll r){
ans=;
dfs(,,,r);
return ans;
} int main(){
ios::sync_with_stdio(false);
cin.tie();
int T;
int x,p,k;
cin>>T;
while(T--){
cin>>x>>p>>k;
init(p);
ll t=count(x);
ll l=x,r=1e18,m=(l+r)>>;
while(l<r){
if(count(m)-t>=k)r=m;
else l=m+;
m=(l+r)>>;
}
cout<<m<<endl;
}
return ;
}

Codeforces 920G - List Of Integers的更多相关文章

  1. Codeforces 920G List Of Integers 二分 + 容斥

    题目链接 题意 给定 \(x,p,k\),求大于 \(x\) 的第 \(k\) 个与 \(p\) 互质的数. 思路 参考 蒟蒻JHY. 二分答案 \(y\),再去 \(check\) 在 \([x,y ...

  2. codeforces 1269 E K Integers

    E. K Integers 题目连接:https://codeforces.com/contest/1269/problem/E 题意 给了一个排列p,你每次操作可以交换两个相邻的元素,现在问你最少操 ...

  3. Codeforces 920G(二分+容斥)

    题意: 定义F(x,p)表示的是一个数列{y},其中gcd(y,p)=1且y>x 给出x,p,k,求出F(x,p)的第k项 x,p,k<=10^6 分析: 很容易想到先二分,再做差 然后问 ...

  4. Codeforces Educational Round 37

    Solved   CodeForces 920A Water The Garden   Solved   CodeForces 920B Tea Queue   Solved   CodeForces ...

  5. Codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers 高精度比大小,模拟

    A. Comparing Two Long Integers 题目连接: http://www.codeforces.com/contest/616/problem/A Description You ...

  6. codeforces Round #440 A Search for Pretty Integers【hash/排序】

    A. Search for Pretty Integers [题目链接]:http://codeforces.com/contest/872/problem/A time limit per test ...

  7. Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)

    G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...

  8. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  9. Educational Codeforces Round 5 A. Comparing Two Long Integers

    A. Comparing Two Long Integers time limit per test 2 seconds memory limit per test 256 megabytes inp ...

随机推荐

  1. 关于__declspec(dllexport)

    windows下dll动态库函数的导入与导出. __declspec Microsoft Specific __declspec ( extended-attribute ) declarator l ...

  2. MQ选型对比RabbitMQ RocketMQ ActiveMQ Kafka(外加redis对比及其实现)

    rocketmq 4.3开始支持事务https://www.cnblogs.com/hzmark/p/rocket_txn.html 参考:rabbitMQ.activeMQ.zeroMQ.Kafka ...

  3. 使用UI管理docker

    比较全面的对比 wangzi19870227 比较推荐的有两种(http://dockone.io/article/225): Shipyard 和 dockerui https://docs.doc ...

  4. kali linux 2.0配置更新源后apt-get update 报错

    这个是我/etc/apt/sources.list的更新源: deb http://http.kali.org/kali kali-rolling main contrib non-free deb ...

  5. MS08_067漏洞渗透攻击实践

    MS08_067漏洞渗透攻击实践 实验前准备 1.两台虚拟机,其中一台为kali,一台为windows xp sp3(英文版). 2.在VMware中设置两台虚拟机网络为NAT模式,自动分配IP地址, ...

  6. kaptcha验证码实现,配合spring boot使用

    一.kaptcha介绍 Kaptcha是谷歌放在github上的一个验证码jar包,我们可以简单配置属性实现验证码的验证功能. kaptcha参数设置如下所示: Constant 描述 默认值 kap ...

  7. repo总结【转】

    本文转载自:https://blog.csdn.net/weixin_38599972/article/details/78982408 1. repo start  ##创建并切换分支repo st ...

  8. Markdown语法参考

    参考博客: https://www.jianshu.com/p/f3147a804368 https://www.jianshu.com/p/191d1e21f7ed https://www.jian ...

  9. Linux下使用wget下载FTP服务器文件

    wget -nH -m --ftp-user=your_username --ftp-password=your_password ftp://your_ftp_host/* 使用命令下载ftp上的文 ...

  10. .net 打包下载

      ZipArchive 打包下载 private IActionResult DownloadZipFromUrl(string[] guids,string zipFullName) { usin ...