Smallest power of 6 whose decimal expansion contains n: Difference between revisions

Add C++
(Add C)
(Add C++)
Line 55:
8: 2176782336
9: 1296
10: 10077696
11: 2821109907456
12: 1296
13: 13060694016
14: 6140942214464815497216
15: 101559956668416
16: 216
17: 60466176
18: 470184984576
19: 21936950640377856
20: 170581728179578208256
21: 216</pre>
 
=={{header|C++}}==
<lang cpp>#include <iostream>
#include <iomanip>
#include <string>
#include <gmpxx.h>
 
std::string smallest_six(unsigned int n) {
mpz_class pow = 1;
std::string goal = std::to_string(n);
while (pow.get_str().find(goal) == std::string::npos) {
pow *= 6;
}
return pow.get_str();
}
 
int main() {
for (unsigned int i=0; i<22; i++) {
std::cout << std::setw(2) << i << ": "
<< smallest_six(i) << std::endl;
}
return 0;
}</lang>
 
{{out}}
<pre> 0: 10077696
1: 1
2: 216
3: 36
4: 46656
5: 46656
6: 6
7: 7776
8: 2176782336
9: 1296
10: 10077696
11: 2821109907456
2,112

edits