蓝桥杯_第k个幸运的数#include<bits/stdc++.h>using namespace std;typedef long long LL;const LL MAX = 59084709587505; //本题中的数int main(){ int a[3]={3,5,7}; LL t = 1; set<LL> s; //set集合排序加去重 while(1) { for(int i=0;i<3;i++) //生成数 { LL tt = t * a[i]; if(tt<=MAX) s.insert(tt); } t = *(s.upper_bound(t)); //找出s中略大于t的数赋值给t if(t>=MAX) break; //结束循环 } cout<<s.size()<<endl;}================解释:头文件:lower_bound和upper_bound在头文件algorithm中。 解释:lower_bound和upper_bound为二分法查找元素,其时间复杂度为O(log n)。#include<iostream>#include<algorithm>#include<set>using namespace std;int main(){ set<int> s{ 1,2,1,9,7 };//原本就有序 set<int>::iterator it1 = s.lower_bound(2); cout << *it1 << endl;//*it1=2 set<int>::iterator it2 = s.upper_bound(2); cout << *it2 << endl;//*it2=7 system("pause"); return 0;}