zoukankan      html  css  js  c++  java
  • CodeForces460B. Little Dima and Equation

    B. Little Dima and Equation
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.

    Find all integer solutions x (0 < x < 109) of the equation:

    x = b·s(x)a + c, 

    where abc are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.

    The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: abc. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.

    Input

    The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000;  - 10000 ≤ c ≤ 10000).

    Output

    Print integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.

    Sample test(s)
    input
    3 2 8
    output
    3
    10 2008 13726
    input
    1 2 -18
    output
    0
    input
    2 2 -1
    output
    4
    1 31 337 967

    这道题目比较好,想法,一开始不是我想的,枚举x很不现实, 1 ~ 1亿, 这样枚举肯定超时
    而 s(x) 的范围就很明确, 1~81, 最多 999999999, 也就是9 个 9.所以就会用这个枚举。

    枚举 s(x), 然后验证 是否是 x, 就这样
    也模仿他人, 把那些能省事的宏定义写上,慢慢来吧
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 #define LL long long
     8 #define usLL unsigned LL
     9 #define mz(array) memset(array, 0, sizeof(array))
    10 #define minf(array) memset(array, 0x3f, sizeof(array))
    11 
    12 LL bit_sum(LL x)
    13 {
    14     LL sum = 0;
    15     while(x)
    16     {
    17         sum += x % 10;
    18         x /= 10;
    19     }
    20     return sum;
    21 }
    22 
    23 LL powd(int t,int n){
    24     LL sum=1;
    25     for(int i=1;i<=n;i++)
    26         sum*=t;
    27     return sum;
    28 }
    29 
    30 int main()
    31 {
    32     int a, b, c;
    33     cin >> a >> b >> c;
    34     int ans[100000];
    35     int cnt = 0;
    36     for(int i = 1; i <= 81; i++)
    37     {
    38         LL t = powd(i, a);
    39         LL x = t*b + c;
    40         if(x > 0 && x < 1000000000 && bit_sum(x)==i)
    41         {
    42             ans[cnt++] = x;
    43         }
    44     }
    45 
    46     printf("%d
    ", cnt);
    47     for(int i = 0; i < cnt; i++)
    48     {
    49         printf("%d ", ans[i]);
    50     }
    51     puts("");
    52     return 0;
    53 }
    View Code



  • 相关阅读:
    c#pda(wince)摄像头拍照程序
    单点登录在ASP.NET上的简单实现(图)
    写文件 指定固定开始位置
    关于"System.Web.HttpException: 超过了最大请求长度。"错误的解决
    配置本地YUM:
    开启mysql的审计功能
    用GRE通道连通机房之间的私网
    让nginx支持PATH_INFO
    Linux在本地使用yum安装软件
    sysbench的安装及使用
  • 原文地址:https://www.cnblogs.com/ya-cpp/p/4340580.html
Copyright © 2011-2022 走看看