分析:f(x)和x是相关联的,枚举其中一个,通过计算得到另一个,再判断时候合法即可. 因为f(x)最多只有81,枚举f(x)即可.
#include#include #include #include using namespace std;typedef long long ll;const int maxn = 110;int T;ll a,b,c,k,ans,anss[maxn],tot;ll check(ll x){ ll res = 0; while (x) { res += x % 10; x /= 10; } return res;}ll qpow(ll a,ll b){ ll res = 1; while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res;}int main(){ //freopen("test.txt","r",stdin); //freopen("safe.out","w",stdout); scanf("%d",&T); while (T--) { ans = 0; tot = 0; scanf("%lld%lld%lld%lld",&a,&b,&c,&k); for (ll i = 0; i <= 81; i++) { ll temp = qpow(i,a) * b + c; if (temp >= 0 && temp <= k) { if (check(temp) == i) { ans++; anss[++tot] = temp; } } } if (ans == 0) printf("0\n-1\n"); else { sort(anss + 1,anss + 1 + tot); printf("%lld\n",ans); for (int i = 1; i <= tot; i++) printf("%lld ",anss[i]); printf("\n"); } } return 0;}