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 }
  • 相关阅读:
    python实战===教你用微信每天给女朋友说晚安
    [go]beego获取参数/返回参数
    [go]os.Open方法源码
    [go]从os.Stdin探究文件类源码
    [svc]linux中的文件描述符(file descriptor)和文件
    [net]tcp和udp&socket
    [django]update_or_create使用场景
    [sh]shell语法小结
    [drf]访问文档出现错误'AutoSchema' object has no attribute 'get_link'
    [py]python操作zookeeper
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5492841.html
Copyright © 2011-2022 走看看