当前位置:网站首页>B. Construct a simple sequence (greedy)
B. Construct a simple sequence (greedy)
2022-08-04 14:18:00 【Harris-H】
B.Construct a simple sequence of numbers(贪心)
Whether each judgment satisfies the mutual prime,Not satisfied to join the candidate queue,Then when one is satisfied, add the queue to the back.
#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int main(){
int n;
cin>>n;
while(n--){
int x,y;
cin>>x>>y;
a[1]=x;
int cnt=1;
queue<int>q;
for(int i=1;cnt<=y;i++){
if(i==x)continue;
if(__gcd(a[cnt],i)==1){
a[++cnt]=i;
while(!q.empty()){
a[++cnt]=q.front();
q.pop();
}
}
else{
q.push(i);
}
}
cout<<a[y]<<"\n";
}
return 0;
}
边栏推荐
- 从理论到实践:MySQL性能优化和高可用架构,一次讲清
- Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source
- 解题-->在线OJ(十八)
- 让Web页面中的编辑器支持黏贴或直接拖拽来添加图片「建议收藏」
- 异步编程概览
- odoo15 大部分模块都用的附件整理成一独立模块
- 人像分割技术解析与应用
- BZOJ 1798 维护序列 (多校连萌,对线段树进行加乘混合操作)
- 如何通过使用“缓存”相关技术,解决“高并发”的业务场景案例?
- SQL语句的写法:Update、Case、 Select 一起的用法
猜你喜欢
随机推荐
[in-depth study of 4 g / 5 g / 6 g project - 50] : URLLC - 16 - the 3 GPP URLLC agreement, specification, technical principle of depth interpretation - 10 - high reliability technology - 1 - low codin
How to play the Tower of Hanoi
编译型与解释型编程语言的区别
Convolutional Neural Network Basics
SQL语句的写法:Update、Case、 Select 一起的用法
CCF GLCC正式开营|九州云开源专家携丰厚奖金,助力高校开源推广
【问题解决】QT更新组件出现 “要继续此操作,至少需要一个有效且已启用的储存库”
Crawler - basic use of selenium, no interface browser, other uses of selenium, cookies of selenium, crawler cases
Is there a replacement for the LM2596?LM2576 can
信创是什么意思?涉及哪些行业?为什么要发展信创?
如何查找endnote文献中pdf文件的位置
The Internet of things application development trend
MPLS实验
BZOJ 1798 维护序列 (多校连萌,对线段树进行加乘混合操作)
nVisual secondary development - Chapter 2 nVisual API operation guide Swagger use
How to Identify Asynchronous I/O Bottlenecks
AlphaFold 如何实现 AI 在结构生物学中的全部潜力
Almost all known protein structures in the world are open sourced by DeepMind
How to install postgresql and configure remote access in ubuntu environment
idea removes spark logs