solution.md 2.8 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
到x星球旅行的游客都被发给一个整数,作为游客编号。  
x星的国王有个怪癖,他只喜欢数字3,5和7。  
国王规定,游客的编号如果只含有因子:3,5,7,就可以获得一份奖品。  

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

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

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

每日一练社区's avatar
每日一练社区 已提交
15
以下选项<span style="color:red">错误</span>的是?
每日一练社区's avatar
每日一练社区 已提交
16 17

## aop
F
fix bug  
feilong 已提交
18

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

每日一练社区's avatar
每日一练社区 已提交
21
```cpp
每日一练社区's avatar
每日一练社区 已提交
22
#include <bits/stdc++.h>
每日一练社区's avatar
每日一练社区 已提交
23 24 25
using namespace std;
```
### after
F
fix bug  
feilong 已提交
26

每日一练社区's avatar
每日一练社区 已提交
27 28 29 30 31
```cpp

```

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

每日一练社区's avatar
每日一练社区 已提交
33
```cpp
每日一练社区's avatar
每日一练社区 已提交
34 35
typedef long long LL;
const LL MAX = 59084709587505;
每日一练社区's avatar
每日一练社区 已提交
36 37
int main()
{
每日一练社区's avatar
每日一练社区 已提交
38 39 40
    int a[3] = {3, 5, 7};
    LL tou = 1;
    set<LL> s;
每日一练社区's avatar
每日一练社区 已提交
41 42
    while (true)
    {
每日一练社区's avatar
每日一练社区 已提交
43

每日一练社区's avatar
每日一练社区 已提交
44 45
        for (int i = 0; i < 3; i++)
        {
每日一练社区's avatar
每日一练社区 已提交
46 47 48
            LL tt = tou * a[i];
            if (tt <= MAX)
                s.insert(tt);
每日一练社区's avatar
每日一练社区 已提交
49
        }
每日一练社区's avatar
每日一练社区 已提交
50 51 52
        tou = s.upper_bound(tou);
        if (tou >= MAX)
            break;
每日一练社区's avatar
每日一练社区 已提交
53
    }
每日一练社区's avatar
每日一练社区 已提交
54
    cout << s.size() << endl;
每日一练社区's avatar
每日一练社区 已提交
55 56 57 58 59
    return 0;
}
```
## 选项

F
fix bug  
feilong 已提交
60

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

每日一练社区's avatar
每日一练社区 已提交
63
```cpp
每日一练社区's avatar
每日一练社区 已提交
64 65 66
#define LL long long
LL maxs = 59084709587505;
set<LL> q;
每日一练社区's avatar
每日一练社区 已提交
67 68
int main()
{
每日一练社区's avatar
每日一练社区 已提交
69 70 71 72 73 74 75
    q.insert(3);
    q.insert(5);
    q.insert(7);
    set<LL>::iterator it;
    it = q.begin();
    LL mid;
    while (*it <= maxs)
每日一练社区's avatar
每日一练社区 已提交
76
    {
每日一练社区's avatar
每日一练社区 已提交
77 78 79 80 81
        mid = *it;
        q.insert(mid * 3);
        q.insert(mid * 5);
        q.insert(mid * 7);
        it++;
每日一练社区's avatar
每日一练社区 已提交
82
    }
每日一练社区's avatar
每日一练社区 已提交
83 84 85 86 87 88 89
    int num = 0;
    for (it = q.begin(); it != q.end(); it++)
    {
        if (*it <= maxs)
            num++;
    }
    cout << num;
每日一练社区's avatar
每日一练社区 已提交
90 91 92 93 94
    return 0;
}
```

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

每日一练社区's avatar
每日一练社区 已提交
96
```cpp
每日一练社区's avatar
每日一练社区 已提交
97 98 99 100 101
typedef long long LL;
const LL Max = 59084709587505;
int a[3] = {3, 5, 7};

void Find(LL Max)
每日一练社区's avatar
每日一练社区 已提交
102
{
每日一练社区's avatar
每日一练社区 已提交
103 104 105
    set<LL> se;
    LL t = 1;
    while (1)
每日一练社区's avatar
每日一练社区 已提交
106
    {
每日一练社区's avatar
每日一练社区 已提交
107
        for (int i = 0; i < 3; ++i)
每日一练社区's avatar
每日一练社区 已提交
108
        {
每日一练社区's avatar
每日一练社区 已提交
109 110 111
            LL tt = t * a[i];
            if (tt <= Max)
                se.insert(tt);
每日一练社区's avatar
每日一练社区 已提交
112
        }
每日一练社区's avatar
每日一练社区 已提交
113 114 115
        t = *se.upper_bound(t);
        if (t == Max)
            break;
每日一练社区's avatar
每日一练社区 已提交
116
    }
每日一练社区's avatar
每日一练社区 已提交
117
    cout << se.size() << endl;
每日一练社区's avatar
每日一练社区 已提交
118
}
每日一练社区's avatar
每日一练社区 已提交
119 120
int main(void)
{
每日一练社区's avatar
每日一练社区 已提交
121

每日一练社区's avatar
每日一练社区 已提交
122 123 124 125
    Find(Max);

    return 0;
}
每日一练社区's avatar
每日一练社区 已提交
126 127 128
```

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

每日一练社区's avatar
每日一练社区 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143
```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)
每日一练社区's avatar
每日一练社区 已提交
144
        {
每日一练社区's avatar
每日一练社区 已提交
145 146 147 148 149 150
            cout << times << endl;
            return 0;
        }
        times++;
        for (int i = 0; i < 3; i++)
        {
每日一练社区's avatar
每日一练社区 已提交
151
            long long b = lucky * ok[i];
每日一练社区's avatar
每日一练社区 已提交
152 153 154 155 156 157 158 159 160 161
            if (!st.count(b))
            {
                st.insert(b);
                pq.push(b);
            }
        }
    }
    return 0;
}
```