Smallest power of 6 whose decimal expansion contains n: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add Haskell) |
Not a robot (talk | contribs) (Add C) |
||
Line 6: | Line 6: | ||
=={{header|C}}== |
|||
<lang C>#include <stdio.h> |
|||
#include <string.h> |
|||
#include <gmp.h> |
|||
char *power_of_six(unsigned int n, char *buf) { |
|||
mpz_t p; |
|||
mpz_init(p); |
|||
mpz_ui_pow_ui(p, 6, n); |
|||
mpz_get_str(buf, 10, p); |
|||
mpz_clear(p); |
|||
return buf; |
|||
} |
|||
char *smallest_six(unsigned int n) { |
|||
static char nbuf[32], powbuf[1024]; |
|||
unsigned int p = 0; |
|||
do { |
|||
sprintf(nbuf, "%u", n); |
|||
power_of_six(p++, powbuf); |
|||
} while (!strstr(powbuf, nbuf)); |
|||
return powbuf; |
|||
} |
|||
int main() { |
|||
unsigned int i; |
|||
for (i=0; i<22; i++) { |
|||
printf("%d: %s\n", i, smallest_six(i)); |
|||
} |
|||
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 |
|||
12: 1296 |
|||
13: 13060694016 |
|||
14: 6140942214464815497216 |
|||
15: 101559956668416 |
|||
16: 216 |
|||
17: 60466176 |
|||
18: 470184984576 |
|||
19: 21936950640377856 |
|||
20: 170581728179578208256 |
|||
21: 216</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
Line 117: | Line 178: | ||
Real: 00:00:00.066 |
Real: 00:00:00.066 |
||
</pre> |
</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |