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 ...
随机推荐
- Strom学习笔记2:Storm Maven Project-StromStack工程
1:IntelliJ新建Maven工程
- 02: flask 使用举例
1.1 项目说明 https://github.com/rickyyangrui/Flask_web_demo1 1.项目文件结构 2.项目主文件 cssmin==0.2.0 Flask==0.1 ...
- Python邮件发送脚本(Linux,Windows)通用
脚本 #!/usr/bin/python #-*- coding:utf-8 -*- #Python Mail for chenglee #if fileformat=dos, update file ...
- Iterator和Iterable的区别以及使用
Iterator和Iterable的区别以及使用 1.什么是迭代器 迭代器(iterator)是一种对象,它能够用来遍历标准模板库容器中的部分或全部元素,每个迭代器对象代表容器中的确定的地址.迭代 ...
- VC++使用MapFileAndCheckSum完成自检测
转载:https://blog.csdn.net/lekonpeng/article/details/4150464 当我们完成一个工程,编译成可执行文件后,一般是不希望这个可执行文件被人改动的,那么 ...
- iOS 允许后台任务吗?
个人整理 1,用户层: 低电量模式 App后台数据刷新 的开关会影响App后台运行 2, 10分钟时间 后台任务: 在AppDelegate中加入以下代码:不受1影响 - (void)applic ...
- Bytom猜谜合约使用指南
准备工作: 1.安装全节点钱包V1.0.5以上并同步完成: 2.已经发行一种资产,发行资产的方法具体见文章<如何在Bytom上发布资产?> 3.准备好一些BTM作为手续费: 设置谜语(锁定 ...
- eclipse创建springBoot项目
创建Spring Boot 工程 先在eclipse中安装spring -tool -suite插件,然后根据以下步骤可以创建1.新建Spring Starter Project 2.Packagin ...
- KNN——图像分类
内容参考自:https://zhuanlan.zhihu.com/p/20894041?refer=intelligentunit 用像素点的rgb值来判断图片的分类准确率并不高,但是作为一个练习kn ...
- BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊(分块)
http://www.lydsy.com/JudgeOnline/problem.php?id=2002 题意: 思路:不会LCT,就只好用分块了. 将这n个数分成根号n块,对于每一块中的每一个数,处 ...