当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
化繁为简,聊一聊复制状态机系统架构抽象
企业应当实施的5个云安全管理策略
Lixia Action | Kyushu Yunzhang Jinnan: Open source is not a movement for a few people, popularization is the source
Convolutional Neural Network Basics
"C pitfalls and pitfalls" reading summary
如何查找endnote文献中pdf文件的位置
《社会企业开展应聘文职人员培训规范》团体标准在新华书店上架
Analysis and application of portrait segmentation technology
第六届未来网络发展大会,即将开幕!
MySQL【触发器】
随机推荐
中大型商业银行堡垒机升级改造就用行云管家!必看!
橄榄枝大课堂APP正式启动上线
谷歌插件.crx文件下载后被自动删除的解决方法
token 过期后,如何自动续期?
Execution failed for task ‘:xxx:generateReleaseRFile‘.
化算力为战力:宁夏中卫的数字化转型启示录
idea permanent activation tutorial (new version)
解题-->在线OJ(十八)
Makefile 语法及使用笔记
【问题解决】QT更新组件出现 “要继续此操作,至少需要一个有效且已启用的储存库”
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
量化细胞内的信息流:机器学习时代下的研究进展
Qt的QItemDelegate使用
ssm learning experience (final chapter)
广告电商系统开发功能只订单处理
CCF GLCC正式开营|九州云开源专家携丰厚奖金,助力高校开源推广
Theory 1: Deep Learning - Detailed Explanation of the LetNet Model
字符串类的设计与实现_C语言字符串编程题
Sum of four squares, laser bombs
第六届未来网络发展大会,即将开幕!