当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Rust from entry to proficient 04-variables
两款移相振荡器的对比
SLAM 05.视觉里程计-2-特征法
【硬件架构的艺术】学习笔记(1)亚稳态的世界
谷歌插件.crx文件下载后被自动删除的解决方法
ICML 2022 | 图神经网络的局部增强
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
解题-->在线OJ(十八)
Almost all known protein structures in the world are open sourced by DeepMind
State security organs conduct criminal arrest and summons review on Yang Zhiyuan, a suspect suspected of endangering national security
随机推荐
Phasecraft连下两城,助力英国量子技术商业化加速!
leetcode 48. Rotate Image (Medium)
C# winforms 输入颜色转换颜色名
[深入研究4G/5G/6G专题-50]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-10-高可靠性技术-1-低编码率编码调制方案MCS与高可靠性DRB
AlphaFold 如何实现 AI 在结构生物学中的全部潜力
Theory 1: Deep Learning - Detailed Explanation of the LetNet Model
浙江大学团队使用基于知识图谱的新方法,从空间分辨转录组数据中推断细胞间通信状况
Rust from entry to proficient 04-variables
集合划分差最小问题(01背包)
leetcode 48. Rotate Image 旋转图像(Medium)
Lecture 4 SVN
CCF GLCC正式开营|九州云开源专家携丰厚奖金,助力高校开源推广
《社会企业开展应聘文职人员培训规范》团体标准在新华书店上架
砺夏行动|九州云章津楠:开源不是少数人的运动,大众化才是源泉
nVisual secondary development - Chapter 2 nVisual API operation guide Swagger use
人像分割技术解析与应用
G. Mountaineering Squad (violence & dfs)
数据库恢复
CF1527D MEX Tree (mex & tree & inclusive)
快解析结合千方百剂