当前位置:网站首页>B.构造一个简单的数列(贪心)
B.构造一个简单的数列(贪心)
2022-08-04 14:09:00 【Harris-H】
B.构造一个简单的数列(贪心)
每次判是否满足互质,不满足加入到备选队列,然后遇到一个满足的后把队列的加到后面即可。
#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;
}
边栏推荐
猜你喜欢
Interviewer: Tell me the difference between NIO and BIO
Fuse bit of AVR study notes
SLAM 05.视觉里程计-2-特征法
量化细胞内的信息流:机器学习时代下的研究进展
This article sorts out the development of the main models of NLP
[LeetCode] 38. Appearance sequence
nVisual二次开发——第二章 nVisual API操作指南Swagger使用
AutoCAD DWG,DXF文件导出高清图片、PDF
国家安全机关对涉嫌危害国家安全犯罪嫌疑人杨智渊实施刑事拘传审查
砺夏行动|九州云章津楠:开源不是少数人的运动,大众化才是源泉
随机推荐
Is the code more messy?That's because you don't use Chain of Responsibility!
化繁为简,聊一聊复制状态机系统架构抽象
Keycloak 6.0.0 正式发布,身份和访问管理系统
Theory 1: Deep Learning - Detailed Explanation of the LetNet Model
Button control switch 4017 digital circuit chip
【无标题】
MPLS实验
Week 7 Latent Variable Models and Expectation Maximization
烂大街的缓存穿透、缓存击穿和缓存雪崩,你真的懂了?
word2003按空格键为什么会出现小数点
Chinese valentine's day, of course, to learn SQL optimization better leave work early to find objects
Problem solving-->Online OJ (18)
并发刺客(False Sharing)——并发程序的隐藏杀手
idea removes spark logs
leetcode 48. Rotate Image (Medium)
idea去掉spark的日志
AVR学习笔记之熔丝位
第六届未来网络发展大会,即将开幕!
SQL语句的写法:Update、Case、 Select 一起的用法
如何才能有效、高效阅读?猿辅导建议“因材因时施教”