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



  • 相关阅读:
    恢复计算机崩溃数据的五款最佳Linux发行版
    不敢想象!Vim使用者的“大脑”竟是这样
    开发者和系统管理者最喜爱的开源工具Vim 起步学习的五个技巧
    .NET程序与CA对接一直提示重定向
    覆盖原有div或者Input的鼠标移上去描述
    IOS9以上如何导入铃声并设置
    c# 动态调用webserver
    没有终结点在侦听可以接受消息的*这通常是由于不正确的地址或者 SOAP操作导致的
    url 参数的加号变成空格处理
    在git 服务器挂载、创建新的项目、克隆新的项目
  • 原文地址:https://www.cnblogs.com/ya-cpp/p/4340580.html
Copyright © 2011-2022 走看看