当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
Redis 复习计划 - Redis主从数据一致性和哨兵机制
idea permanent activation tutorial (new version)
国家安全机关对涉嫌危害国家安全犯罪嫌疑人杨智渊实施刑事拘传审查
智能电视可以打开小程序应用,再也不用头痛内存了
开发者独立搭建一个跨模态搜索应用有多难?
从理论到实践:MySQL性能优化和高可用架构,一次讲清
ACL 2022 | 社会科学理论驱动的言论建模
谁说 Mysql 单表最大 2000 W ?我硬要塞它 1 个亿
Win11勒索软件防护怎么打开?Win11安全中心勒索软件防护如何设置
PAT甲级:1040 Longest Symmetric String
Kyushu Cloud attended the Navigator Online Forum to discuss the current status, challenges and future of 5G MEC edge computing
oracle+RAC+linux5.1所需要安装的包
七夕当然要学会SQL优化好早点下班去找对象
CCF GLCC officially opened | Kyushu Cloud open source experts bring generous bonuses to help universities promote open source
centos7安装mysql急速版
Problem solving-->Online OJ (18)
基于 Next.js实现在线Excel
中大型商业银行堡垒机升级改造就用行云管家!必看!
[Niu Ke brush questions-SQL big factory interview questions] NO5. Analysis of a treasure store (e-commerce model)
LeetCode 1403 Minimum subsequence in non-increasing order [greedy] HERODING's LeetCode road