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
using namespace std;
```
每日一练社区's avatar
每日一练社区 已提交
25

每日一练社区's avatar
每日一练社区 已提交
26
### after
F
fix bug  
feilong 已提交
27

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

```

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

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

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

F
fix bug  
feilong 已提交
61

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

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

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

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

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

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

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

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

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