LQB201804第几个幸运数

 

 我自己一开始想的差不多,但是好像想得是vector+sort....

直接用set它不香吗?

还有就是寻找下一个数的时候,没有用upperbound,,,

我想的大概是遍历一遍(就是用for对这个函数进行实现)

但是很慢,,,

那就s.upper_bound

 1 #include <iostream>
 2 #include <set>//话说我连头文件都忘记了
 3 using namespace std;
 4 
 5 #define MAX  59084709587505
 6 #define LL  long long
 7 int main(){
 8     int a[3]={3,5,7};
 9     LL t=1;
10     set <LL> s;
11     while(1){
12     for (int i = 0; i < 3; ++i) {
13         LL temp = t * a[i];
14         if(temp<=MAX)//一个小特判尽显心机
15         s.insert(temp);
16 
17     }
18 
19        t=*(s.upper_bound(t));
20         if(t==MAX){
21             cout<<s.size();
22             break;
23         }
24     }
25 
26 
27 
28 
29 
30 
31 
32 
33 }

 

posted @ 2020-07-07 15:58  安之若醇  阅读(144)  评论(0编辑  收藏  举报
Live2D服务支持