-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC++.cpp
106 lines (97 loc) · 1.86 KB
/
C++.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
70
71
72
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
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int base;
string convertFromDecimalToAnyBase(int n)
{
string number = "";
while (n != 0)
{
int reste = n % base;
n = (n - reste) / base;
number += b64[reste];
}
reverse(number.begin(), number.end());
return number;
}
class Divider
{
public:
int nBase10;
string nBase;
Divider(int n)
{
nBase10 = n;
nBase = convertFromDecimalToAnyBase(n);
}
};
vector<Divider> dividers;
int convertFromAnyBaseToDecimal(string n)
{
int value = 0;
reverse(n.begin(), n.end());
for (int i = 0; i < n.size(); i++)
{
int iOf = b64.find(n[i]);
value += iOf * pow(base, i);
}
return value;
}
bool isBuzzle(int n)
{
string strValue = convertFromDecimalToAnyBase(n);
for (Divider divider : dividers)
{
if (n % divider.nBase10 == 0)
{
return true;
}
if (strValue.back() == divider.nBase.back())
{
return true;
}
}
if (strValue.size() != 1)
{
int _n = 0;
for (int i = 0; i < strValue.size(); i++)
{
int index = b64.find(strValue[i]);
_n += index;
}
return isBuzzle(_n);
}
return false;
}
int main()
{
int a;
int b;
cin >> base >> a >> b;
cin.ignore();
int k;
cin >> k;
cin.ignore();
for (int i = 0; i < k; i++)
{
int num;
cin >> num;
cin.ignore();
dividers.push_back({num});
}
for (int i = a; i <= b; i++)
{
if (isBuzzle(i))
{
cout << "Buzzle\n";
}
else
{
cout << i << "\n";
}
}
}