#include<bits/stdc++.h>
using namespace std;
using ll = __int128;
// 快速幂
ll ksm(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
// print(__int128)
void print(ll x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) print(x / 10);
putchar(x % 10 + '0');
}
// 计算g(x)
ll cal(ll x) {
if (x < 10) return 0;
ll y = 1;
while (x) {
y *= x%10;
x /= 10;
}
//print(y);
//putchar('\n');
return cal(y)+1;
}
// 通过将work(x)的各个数位相乘得到x,由x反推work(x),不存在为-1
ll work(ll x) {
ll res = 0;
while (x >= 10) {
bool ok = false;
for (int i = 9; i >= 2; i--) {
if (x % i == 0) {
x /= i;
res = res * 10 + i;
ok = true;
break;
}
}
if (!ok) return -1;
}
res = res * 10 + x;
return res;
}
void solve(){
// 设持久度为11的数为x,f(x) = y
// 那么y的持久度为10,且一定可以表示为2^a * 3^b * 5^c * 7^d
for (int i = 0; i <= 63; i++) {
ll t1 = ksm(2, i);
for (int j = 0; ; j ++) {
ll t2 = ksm(3, j);
if (t1 * t2 > 1e18) break;
for (int k = 0; ; k ++) {
ll t3 = ksm(5, k);
if (t1 * t2 * t3 > 1e18) break;
for (int u = 0; ; u ++) {
ll t4 = ksm(7, u);
ll t = t1 * t2 * t3 * t4;
if (t > 1e18) break;
if (cal(t) == 10) {
ll t5 = work(t);
if (t5 != -1) {
print(t5);
putchar(' ');
}
}
}
}
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
//int T; cin >> T;
//while (T--)
solve();
return 0;
}
全部评论
(0) 回帖