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. 18位身份证验证(Java)

    我的代码: package day20181016;/** * 身份证的验证 34052419800101001X * */import java.util.Scanner;public class ...

  2. 04: nginx部署vue

    1.1 基本配置 server { listen 9000; server_name 1.1.1.3; #access_log logs/access_example.log main; root / ...

  3. python简说(二十三)发邮件

    import yagmailusername='uitestp4p@163.com'password='houyafan123'#生成授权码,qq.163.126都是授权码 mail_server = ...

  4. 深入浅出MyBatis-快速入门

    http://blog.csdn.net/hupanfeng/article/details/9068003/

  5. UML状态机图【图3】--☆

    UML状态机图 基本概述    状态机图描述的是围绕某一事物状态变化的图.它也是三大流程分析利器之一.它和活动图的区别在于,活动图是描述事物发生的流程,是多个角色参与的,而状态机描述的是事物的状态变化 ...

  6. 【Python56--爬取妹子图】

    爬取网站的思路 第一步:首先分析爬取网站的连接地址特性,发现翻页图片的时候连接:http://www.mmjpg.com/mm/1570  ,http://www.mmjpg.com/mm/1569, ...

  7. 【Python48--魔法方法:迭代器&生成器】

    一.迭代器 1.iter() __iter__() 2.next() __next__() 二.用while语句实现for语句相同的功能 for each in range(5): print(eac ...

  8. 在Linux系统上卸载playOnLinux

    1.remove just the playonlinux package itself. sudo apt-get remove playonlinux 2.remove the playonlin ...

  9. JDK8新特性:使用Optional避免null导致的NullPointerException

    空指针异常是导致Java应用程序失败的最常见原因.以前,为了解决空指针异常,Google公司著名的Guava项目引入了Optional类,Guava通过使用检查空值的方式来防止代码污染,它鼓励程序员写 ...

  10. JQ插入节点方法

    1.append()  appendTo()  prepend() prependTo() 2. before() insertBefore() after() insertAfter()