Codeforces 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的更多相关文章
- Codeforces 920G List Of Integers 二分 + 容斥
题目链接 题意 给定 \(x,p,k\),求大于 \(x\) 的第 \(k\) 个与 \(p\) 互质的数. 思路 参考 蒟蒻JHY. 二分答案 \(y\),再去 \(check\) 在 \([x,y ...
- codeforces 1269 E K Integers
E. K Integers 题目连接:https://codeforces.com/contest/1269/problem/E 题意 给了一个排列p,你每次操作可以交换两个相邻的元素,现在问你最少操 ...
- Codeforces 920G(二分+容斥)
题意: 定义F(x,p)表示的是一个数列{y},其中gcd(y,p)=1且y>x 给出x,p,k,求出F(x,p)的第k项 x,p,k<=10^6 分析: 很容易想到先二分,再做差 然后问 ...
- Codeforces Educational Round 37
Solved CodeForces 920A Water The Garden Solved CodeForces 920B Tea Queue Solved CodeForces ...
- 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 ...
- 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 ...
- 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 ...
- codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers
题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...
- 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 ...
随机推荐
- VScode 好用插件集合(一)
VScode 好用插件集合(一) 什么是VScode Visual Studio Code (简称 VS Code / VSC) 是一款免费开源的现代化轻量级代码编辑器,支持几乎所有主流的开发语言的语 ...
- face_recognition 基础接口
face_recognition 基础接口 face_recognition使用世界上最简单的人脸识别库,在Python或命令行中识别和操作人脸. 使用dlib最先进的人脸识别技术构建而成,并具有深度 ...
- 病毒注册表常用目标Svchost和Explorer
Windows系统的Svchost.exe和Explorer.exe两种进程,作为Windows系统中两种重要的进程,下面我们就来看看他们的特点以及在各个操作系统中的应用. Explorer.exe ...
- k8s build new API
apiserver-builder git hub api conventions storage api arch step by step, we can follow it. api con ...
- amqp 抓包
1. wireshark 2. tcpick -yR -r file.name
- python --- 15 装饰器
装饰器 一.原则,目的 开闭原则: 对功能的扩展开放,对代码的修改是封闭的(不可修改的) 目的:在目标函数前或后插入一段新的代码,不改变源代码 二.装饰器的通用语法 三.多个装饰器修饰同一个函数 ...
- ODAC(V9.5.15) 学习笔记(十三)TOraMetaData
通过TOraMetaData控件获取Oracle数据库对象信息,首先需要设置MetaDataKind属性,然后设置Restrictions属性设置条件,最后通过激活数据集获取信息,演示代码如下: Me ...
- Python3 tkinter基础 Frame bind 捕捉多键同时按
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- Python3基础 list insert 在指定位置挤入一个元素
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 真心觉得没有必要使用dock和kde桌面
在安装了, 并使用cairo-dock后, 如果不使用 cairo-dock(fallback mode) 或不启用硬件加速, 将导致 cpu的使用率一直是100%, 而且风扇响的太厉害. 说明doc ...