zoukankan      html  css  js  c++  java
  • B

    B - Little Dima and Equation
    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

    Description

    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 Input

    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。

    附AC代码:

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 using namespace std;
     6 long long num[100];
     7 int main()
     8 {
     9     long long a,b,c;
    10     while(~scanf("%I64d %I64d %I64d",&a,&b,&c)){
    11     long long n,ans=0,i,sum,s,j;
    12     long long x,temp;
    13         for(i=1;i<=81;i++)//s(x)最大为81 
    14     {
    15         s=1;
    16         for(j=1;j<=a;j++)
    17             s*=i;//做a次方运算 
    18         x=s*b+c;
    19         sum=0;
    20         temp=x;
    21         while(temp)
    22         {
    23             sum+=temp%10;
    24             temp/=10;
    25         }
    26         if(sum==i&&x>=1&&x<1e9)//查找x 
    27         {
    28             num[ans++]=x;
    29         }
    30     }
    31     printf("%I64d
    ",ans);
    32     if(ans!=0){
    33         for(i=0;i<ans-1;i++)
    34     {
    35         printf("%I64d ",num[i]);
    36     }
    37     printf("%I64d
    ",num[ans-1]);
    38     }
    39     }
    40     
    41     return 0;
    42 }
  • 相关阅读:
    一个创业成功者原始资本的快速积累
    个性创业先要聚人气才能赚大钱
    26个字母——女性必读
    100个成功创业经验方法谈
    从老板身上偷学的东西,你能吗?
    18岁29岁创业者的“黄金线” 要把握
    数禾云上数据湖最佳实践
    如何做好技术 Team Leader?
    闲鱼是怎么让二手属性抽取准确率达到95%+的?
    解读:云原生下的可观察性发展方向
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5492841.html
Copyright © 2011-2022 走看看