Codeforces Round #262 (Div. 2) B

B - 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 a, b, c 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: a, b, c. 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
  1. 3 2 8
Output
  1. 3
    10 2008 13726
Input
  1. 1 2 -18
Output
  1. 0
Input
  1. 2 2 -1
Output
  1. 4
    1 31 337 967

题意:给出一个公式x = b·s(x)a + c,其中s(x)为x的各个位的数字之和。给出a,b,c,求x在1~10^9内的所有解。

题解:枚举s(x),算出来x后看看x和s(x)符不符合,x在不在范围内。因为x<=10^9,所以s(x)为0~81,一下就枚举完了。

注意a<=5,81^5已经超int了,要用long long……血的教训

代码:

  1. //#pragma comment(linker, "/STACK:102400000,102400000")
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<iostream>
  5. #include<cstring>
  6. #include<algorithm>
  7. #include<cmath>
  8. #include<map>
  9. #include<set>
  10. #include<stack>
  11. #include<queue>
  12. using namespace std;
  13. #define ll long long
  14. #define usll unsigned ll
  15. #define mz(array) memset(array, 0, sizeof(array))
  16. #define minf(array) memset(array, 0x3f, sizeof(array))
  17. #define REP(i,n) for(i=0;i<(n);i++)
  18. #define FOR(i,x,n) for(i=(x);i<=(n);i++)
  19. #define RD(x) scanf("%d",&x)
  20. #define RD2(x,y) scanf("%d%d",&x,&y)
  21. #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
  22. #define WN(x) prllf("%d\n",x);
  23. #define RE freopen("D.in","r",stdin)
  24. #define WE freopen("1biao.out","w",stdout)
  25. #define mp make_pair
  26. #define pb push_back
  27. vector<int>v;
  28. int a,b,c;
  29. int main(){
  30. int i,j;
  31. ll k;
  32. scanf("%d%d%d",&a,&b,&c);
  33. v.clear();
  34. for(i=;i<=;i++){
  35. k=;
  36. REP(j,a)k*=i;
  37. ll x=k*b+c;
  38. if(x<= || x>=)continue;
  39. int y=x,sum=;
  40. while(y){
  41. sum+=y%;
  42. y/=;
  43. }
  44. if(sum==i)v.pb(x);
  45. }
  46. int maxi=v.size();
  47. printf("%d\n",maxi);
  48. if(maxi>)printf("%d",v[]);
  49. for(i=;i<maxi;i++)
  50. printf(" %d",v[i]);
  51. return ;
  52. }

CF460B Little Dima and Equation (水题?的更多相关文章

  1. fzu 1909 An Equation(水题)

    题目链接:fzu 1909 An Equation 典型的签到题. #include <stdio.h> #include <string.h> bool judge(int ...

  2. B - 楼下水题(扩展欧几里德)

    B - 楼下水题 Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit St ...

  3. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  4. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  5. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  6. CodeForces460B. Little Dima and Equation

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

  7. [poj2247] Humble Numbers (DP水题)

    DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...

  8. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

  9. BZOJ 1303 CQOI2009 中位数图 水题

    1303: [CQOI2009]中位数图 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2340  Solved: 1464[Submit][Statu ...

随机推荐

  1. siege详解

    简介 siege是一款HTTP/FTP负载测试和基准压测工具   Download http://download.joedog.org/siege/siege-latest.tar.gz   安装 ...

  2. RabbitMQ配置文件

    配置文件Config 在Web的可视化管理界面中可以看到一些文件的路径 比如 Config文件的地址 数据库存放的文件夹 log文件的地址 进入到这个文件夹会发现有这些文件,其中example是con ...

  3. 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Section 1 The Two Fundamental Rules (1.5-1.6)

    Stat2.2x Probability(概率)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...

  4. AngularJs ngHref、ngSrc、ngCopy/ngCut/ngPaste

    ngHref 在Angular程序没完成改变链接上用{{hash}}方式绑定的href值的时候,当用户点击该链接会跳到一个错误的页面. 格式:ng-href=”value” value:表达式. 使用 ...

  5. K米--案例分析

    第三次作业- -K米软件评测 第一部分 调研.评测 评测: 下载并使用.描述最简单直观的个人第一次上手体验: 第一次下载打开.这个简介粗矿的界面让偶着实吓了一跳.界面设计的有板有眼.直接了当.就像是在 ...

  6. NSRunLoop && NSTimer

    新的一年的开始,希望大家一切越来越好,越来越开心快乐!!! 定时器及运行循环 NSRunLoop是iOS消息机制的处理模式 NSRunLoop的主要作用:控制NSRunLoop里面线程的执行和休眠,在 ...

  7. redhat安装VMware tools的方法

    如果我们仔细看的话, 就会发现在VMware软件界面的左下角处显示着 "you don't have VMware Tools installed",即我们还没安装VMware T ...

  8. AspectJ基础学习之三HelloWorld(转载)

    AspectJ基础学习之三HelloWorld(转载) 一.创建项目 我们将project命名为:aspectjDemo.然后我们新建2个package:com.aspectj.demo.aspect ...

  9. ES6标准

    1. ES6标准感觉越来越向传统语言靠拢了,以后写到ES6的标准都记录下: ,,]; // =>操作符 array.forEach(v => console.log(v)); 是不是简化了 ...

  10. thinkphp安装 版本 3.1.3

    基础版: 只有thinkphp基础运行功能 完整版:基础运行能力,还有图片.上传等各种处理类(建议下载完整版) 重要的三个变量 define('APP_DEBUG',True); // 定义应用目录d ...