当前位置:网站首页>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;
}
边栏推荐
- License server system does not support this version of this feature
- 化繁为简,聊一聊复制状态机系统架构抽象
- SMART S7-200PLC串行自由口通讯(耐压测试仪)
- 量化细胞内的信息流:机器学习时代下的研究进展
- C# 动态加载卸载 DLL
- 集合划分差最小问题(01背包)
- 博途200/1500PLC多段曲线控温FB(支持40段控温曲线、段曲线搜索、暂停、跳段等功能)
- Execution failed for task ‘:xxx:generateReleaseRFile‘.
- [机缘参悟-60]:《兵者,诡道也》-1-开篇:“死“与“生“都是天道
- ssm learning experience (final chapter)
猜你喜欢
随机推荐
AutoCAD DWG,DXF文件导出高清图片、PDF
[Opportunity Enlightenment-60]: "Soldiers, Stupid Ways"-1- Opening: "Death" and "Life" are the way of heaven
开放麒麟 openKylin 版本规划敲定:10 月发布 0.9 版并开启公测,12 月发布 1.0 版
异步编程概览
SLAM 04.视觉里程计-1-相机模型
如何通过使用“缓存”相关技术,解决“高并发”的业务场景案例?
国家安全机关对涉嫌危害国家安全犯罪嫌疑人杨智渊实施刑事拘传审查
Chinese valentine's day, of course, to learn SQL optimization better leave work early to find objects
卷积神经网络 基础
中大型商业银行堡垒机升级改造就用行云管家!必看!
Qt的QItemDelegate使用
七夕邂逅爱,那人一定在
ICML 2022 | 图神经网络的局部增强
Button control switch 4017 digital circuit chip
企业应当实施的5个云安全管理策略
CF1527D MEX Tree(mex&树&容斥)
G.登山小分队(暴力&dfs)
职场漫谈:为什么越是内卷的行业越有人争着抢着往里冲?好奇怪的说...
ssm学习心得(完结篇
【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常