zoukankan      html  css  js  c++  java
  • 省选模拟赛 至危警告

    分析:f(x)和x是相关联的,枚举其中一个,通过计算得到另一个,再判断时候合法即可. 因为f(x)最多只有81,枚举f(x)即可.

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    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
    -1
    ");
            else
            {
                sort(anss + 1,anss + 1 + tot);
                printf("%lld
    ",ans);
                for (int i = 1; i <= tot; i++)
                    printf("%lld ",anss[i]);
                printf("
    ");
            }
        }
    
        return 0;
    }
  • 相关阅读:
    基于Diff机制的多个状态合并
    do_mmap解读
    Linux对用户态的动态内存管理
    我的WordPress站点
    使用Bochs学习硬件原理
    inode的若干锚
    Use sed and awk to prettify json
    IO完成端口
    如何使用iText制作中文PDF
    Font and PDF
  • 原文地址:https://www.cnblogs.com/zbtrs/p/8716990.html
Copyright © 2011-2022 走看看