solution.md 3.3 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1
# 第几个幸运数
F
fix bug  
feilong 已提交
2

每日一练社区's avatar
每日一练社区 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
到x星球旅行的游客都被发给一个整数,作为游客编号。  
x星的国王有个怪癖,他只喜欢数字3,5和7。  
国王规定,游客的编号如果只含有因子:3,5,7,就可以获得一份奖品。  

我们来看前10个幸运数字是:  
3 5 7 9 15 21 25 27 35 45  
因而第11个幸运数字是:49  

小明领到了一个幸运数字 59084709587505,他去领奖的时候,人家要求他准确地说出这是第几个幸运数字,否则领不到奖品。

请你帮小明计算一下,59084709587505是第几个幸运数字。



## aop
F
fix bug  
feilong 已提交
18

每日一练社区's avatar
每日一练社区 已提交
19
### before
F
fix bug  
feilong 已提交
20

每日一练社区's avatar
每日一练社区 已提交
21 22 23 24 25 26 27 28
```cpp
#include <iostream>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
```
### after
F
fix bug  
feilong 已提交
29

每日一练社区's avatar
每日一练社区 已提交
30 31 32 33 34
```cpp

```

## 答案
F
fix bug  
feilong 已提交
35

每日一练社区's avatar
每日一练社区 已提交
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
```cpp
int main()
{
    set<long long> st;
    priority_queue<long long, vector<long long>, greater<long long>> pq;
    const int ok[3] = {3, 5, 7};
    st.insert(1);
    pq.push(1);
    int times = 0;
    while (true)
    {
        long long lucky = pq.top();
        pq.pop();
        if (lucky == 59084709587505)
        { //49
            cout << times << endl;
            return 0;
        }
        times++;
        for (int i = 0; i < 3; i++)
        {
            long long b = lucky * ok[i];
            if (!st.count(b))
            {
                st.insert(b);
                pq.push(b);
            }
        }
    }
    return 0;
}
```
## 选项

F
fix bug  
feilong 已提交
70

每日一练社区's avatar
每日一练社区 已提交
71
### A
F
fix bug  
feilong 已提交
72

每日一练社区's avatar
每日一练社区 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
```cpp
int main()
{
    set<long long> st;
    priority_queue<long long, vector<long long>, greater<long long>> pq;
    const int ok[3] = {3, 5, 7};
    st.insert(1);
    pq.push(1);
    int times = 0;
    while (true)
    {
        long long lucky = pq.top();
        pq.pop();
        if (lucky == 59084709587505)
        { //49
            cout << times << endl;
            return 0;
        }
        times++;
        for (int i = 0; i < 3; i++)
        {
            long long b = lucky * ok[i + 1];
            if (!st.count(b))
            {
                st.insert(b);
                pq.push(b);
            }
        }
    }
    return 0;
}
```

### B
F
fix bug  
feilong 已提交
107

每日一练社区's avatar
每日一练社区 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
```cpp
int main()
{
    set<long long> st;
    priority_queue<long long, vector<long long>, greater<long long>> pq;
    const int ok[3] = {3, 5, 7};
    st.insert(1);
    pq.push(1);
    int times = 0;
    while (true)
    {
        long long lucky = pq.top();
        pq.pop();
        if (lucky == 59084709587505)
        { //49
            cout << times << endl;
            return 0;
        }
        times++;
        for (int i = 0; i < 3; i++)
        {
            long long b = lucky * ok[i] + 1;
            if (!st.count(b))
            {
                st.insert(b);
                pq.push(b);
            }
        }
    }
    return 0;
}

```

### C
F
fix bug  
feilong 已提交
143

每日一练社区's avatar
每日一练社区 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
```cpp
int main()
{
    set<long long> st;
    priority_queue<long long, vector<long long>, greater<long long>> pq;
    const int ok[3] = {3, 5, 7};
    st.insert(1);
    pq.push(1);
    int times = 0;
    while (true)
    {
        long long lucky = pq.top();
        pq.pop();
        if (lucky == 59084709587505)
        { //49
            cout << times << endl;
            return 0;
        }
        times++;
        for (int i = 0; i < 3; i++)
        {
            long long b = lucky + ok[i];
            if (!st.count(b))
            {
                st.insert(b);
                pq.push(b);
            }
        }
    }
    return 0;
}

```