-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbuzzle.cpp
28 lines (22 loc) · 816 Bytes
/
buzzle.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
#include <bits/stdc++.h>
int sum_of_digits(int n, int base = 10) {
int ret{ 0 };
while ( 0 != n ) { ret += n % base; n /= base; }
return ret;
}
bool buzzle(int num, int base, const std::vector<int>& tests ) {
for ( const auto& i : tests )
if ( (0 == num % i) || (i == num % base) ) return true;
return ( num < base ) ? false : buzzle( sum_of_digits(num, base), base, tests );
}
int main()
{
int base, a, b;
std::cin >> base >> a >> b; std::cin.ignore();
std::vector<int> tests{ ++std::istream_iterator<int>(std::cin),
std::istream_iterator<int>() };
for ( auto num = a; num <= b; ++num ) {
std::cerr << "num : " << num << '\n';
std::cout << ( buzzle(num, base, tests) ? "Buzzle" : std::to_string(num) ) << '\n';
}
}