Factorions: Difference between revisions

(Added AutoHotkey)
(→‎{{header|C++}}: new entry)
Line 246:
The factorions for base 12 are:
1 2
</pre>
 
=={{header|C++}}==
{{trans|C}}
<lang cpp>#include <iostream>
 
class factorion_t {
public:
factorion_t() {
f[0] = 1u;
for (uint n = 1u; n < 12u; n++)
f[n] = f[n - 1] * n;
}
 
bool operator()(uint i, uint b) const {
uint sum = 0;
for (uint j = i; j > 0u; j /= b)
sum += f[j % b];
return sum == i;
}
 
private:
ulong f[12]; //< cache factorials from 0 to 11
};
 
int main() {
factorion_t factorion;
for (uint b = 9u; b <= 12u; ++b) {
std::cout << "factorions for base " << b << ':';
for (uint i = 1u; i < 1500000u; ++i)
if (factorion(i, b))
std::cout << ' ' << i;
std::cout << std::endl;
}
return 0;
}</lang>
{{out}}
<pre>factorions for base 9: 1 2 41282
factorions for base 10: 1 2 145 40585
factorions for base 11: 1 2 26 48 40472
factorions for base 12: 1 2
</pre>
 
Anonymous user