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. node.js 初学(二)—— 搭建注册/登录服务器

    node.js 初学(二)—— 搭建注册/登录服务器 理论上来说,代码实现在理论和实际上是一样的.但实际上来说,他们不是 做一个最简单的用户注册登录功能 1.接口定义: 注册:/user?act=re ...

  2. opencv学习之路(5)、鼠标和滑动条操作

    一.鼠标事件 #include<opencv2/opencv.hpp> #include<iostream> using namespace cv; using namespa ...

  3. Golang中使用kafka

    golang中比较好用的kafka client有 sarama confluent-kafka-go go_kafka_client optiopay-kafka siesta 其中 sarama的 ...

  4. mysql中的中文乱码解决方案, 全部是 这篇文章的内容: https://www.52jbj.com/jbdq/18755.html

    我们自己鼓捣mysql时,总免不了会遇到这个问题:插入中文字符出现乱码,虽然这是运维先给配好的环境,但是在自己机子上玩的时候咧,总得知道个一二吧,不然以后如何优雅的吹牛B. 如果你也遇到了这个问题,咱 ...

  5. 使用msi自动安装系统

    在实际生活中, 还是要尽量使用 自动化 脚本 等来处理/执行问题, 那样更快更省力省时间 要多使用 网络工具, 网络工具在 管理/ 使用网络的过程 中还是很有用的. 要有这种 "多使用网络工 ...

  6. bzoj 2527: [Poi2011]Meteors

    昨天写了一晚,越写复杂度越感觉不对,早上一想果然是假的. (这里n,m,k我就不区分了) 首先一个城市的询问可以很容易的二分 check用树状数组维护区间(区间修改,单点查询的那种) 一次是\(O(n ...

  7. 【做题】POJ3469 Dual Core CPU——第一道网络流

    刚学了Dinic就开始做题,然后就崩了. 题意:若干个任务,可以放在两个CPU中任意一个上完成,各有一定代价.其中又有若干对任务,如果它们不在同一个CPU上完成,会产生额外代价.最小化并输出代价. 一 ...

  8. P3317 [SDOI2014]重建

    思路 变元矩阵树定理可以统计最小生成树边权积的和,将A矩阵变为边权,D变为与该点相连的边权和,K=D-A,求K的行列式即可 把式子化成 \[ \begin{align}&\sum_{T}\pr ...

  9. Docker之Swarm

    Docker学习笔记 — Swarm搭建Docker集群 Swarm在schedule节点运行容器的时候,会根据指定的策略来计算最适合运行容器的节点,目前支持的策略有:spread, binpack, ...

  10. spring配置redis

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...