Codeforces#262_1002

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

3 2 8

output


10 2008 13726

input

1 2 -18

output

0

input

2 2 -1

output


1 31 337 967

虽然是简单的枚举,其实也没那么简单!

这位同学说的好:

不算难的题目,就是暴力枚举,不过枚举也没有那么容易的,而是需要很好的逻辑思维能力,才能在这么段时间内想出问题答案的。

思考:
1 如何找到规律?
2 没有找到规律,暴力搜索?
3 如何暴力搜索?遍历?以那个值作为遍历?
4 以x作为遍历?范围太大,肯定超时。
5 以s(x)作为遍历,s(x)表示x的数位值相加,一个数字的数位值相加范围肯定是很少的,故此可以选定这个值遍历。
6 第5步是关键思考转折点,有点逆向思维的味道。暴力枚举也是可以很巧妙。没那么容易掌握好。

  1. #include <cstring>
  2.  
  3. #include <iostream>
  4.  
  5. #include <algorithm>
  6.  
  7. #include <cstdio>
  8.  
  9. #include <cmath>
  10.  
  11. #include <map>
  12.  
  13. #include <cstdlib>
  14.  
  15. #define M(a,b) memset(a,b,sizeof(a))
  16.  
  17. using namespace std;
  18.  
  19. int res[];
  20.  
  21. int main()
  22.  
  23. {
  24.  
  25. long long a,b,c;
  26.  
  27. scanf("%I64d%I64d%I64d",&a,&b,&c);
  28.  
  29. int count = ;
  30.  
  31. for(int i = ;i<=;i++)
  32.  
  33. {
  34.  
  35. long long aa = ;
  36.  
  37. for(int t = ;t<a;t++)
  38.  
  39. {
  40.  
  41. aa*=i;
  42.  
  43. }
  44.  
  45. if(b*aa+c>||b*aa+c<) continue;
  46.  
  47. int tem = (int)(b*aa+c);
  48.  
  49. int tem1 = tem;
  50.  
  51. //cout<<i<<' '<<tem<<' ';
  52.  
  53. if(tem<&&tem>)
  54.  
  55. {
  56.  
  57. int ans = ;
  58.  
  59. while(tem)
  60.  
  61. {
  62.  
  63. ans += tem%;
  64.  
  65. tem/=;
  66.  
  67. }
  68.  
  69. //cout<<ans<<endl;
  70.  
  71. if(ans==i)
  72.  
  73. res[count++] = tem1;
  74.  
  75. }
  76.  
  77. }
  78.  
  79. printf("%d\n",count);
  80.  
  81. for(int i = ;i<count;i++)
  82.  
  83. {
  84.  
  85. printf("%d ",res[i]);
  86.  
  87. }
  88.  
  89. if(count>)
  90.  
  91. cout<<endl;
  92.  
  93. return ;
  94.  
  95. }

Codeforces#262_1002的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. 关于安装ruby brew 提示失败

    Error running 'requirements_osx_brew_update_system ruby-1.9.3-p551', showing last 15 lines of /Users ...

  2. HDU 5183 Negative and Positive (NP) --Hashmap

    题意:问有没有数对(i,j)(0<=i<=j<n),使得a[i]-a[i+1]+...+(-1)^(j-i)a[j]为K. 解法:两种方法,枚举起点或者枚举终点. 先保存前缀和:a1 ...

  3. 洛谷P3407 散步[分组]

    题目描述 一条道路上,位置点用整数A表示. 当A=0时,有一个王宫.当A>0,就是离王宫的东边有A米,当A<0,就是离王宫的西边有A米. 道路上,有N个住宅从西向东用1-N来标号.每个住宅 ...

  4. 由于log太多导致ubuntu硬盘空间满了,进入不了系统解决办法

    具体现象是在图形界面输入用户名和密码之后,再次提示需要输入用户名和密码. 步骤一:按快捷键进入命令行界面.ctrl+alt+f1. 步骤二:清空文件 clear log cd /var/log sud ...

  5. PAT 1032. 挖掘机技术哪家强(20)

    为了用事实说明挖掘机技术到底哪家强,PAT组织了一场挖掘机技能大赛.现请你根据比赛结果统计出技术最强的那个学校. 输入格式: 输入在第1行给出不超过105的正整数N,即参赛人数.随后N行,每行给出一位 ...

  6. TCP/IP协议中网关和子网掩码概念

    网关: 不同网段的IP是不能直接互通的,需要一个设备来转发,这个设备就是网关,一般就是路由器,那么路由器的地址就是网关地址. 比如192.168.2.31要往192.168.3.31发送一条消息,他们 ...

  7. 写Java也得了解CPU--伪共享

    第一次接触伪共享的概念,是在马丁的博客上:而ifeve也把这一系列博文翻译整理好了.概读了几次,感觉到此概念的重要.因此有了这个系列的第二篇读后总结. 1. 什么是伪共享(False sharing) ...

  8. 修改AssemblyInfo.cs自动生成版本号

    一. 版本号自动生成方法 1.把 AssemblyInfo.cs文件中的[assembly:AssemblyVersion("1.0.0.0")]改成[assembly:Assem ...

  9. jquery submit() 提交失败

    今天写一个表单提交 居然走到$('#wechat_form').submit() 这,但怎么都没有提交这个表单 google 了一下 Additional Notes:Forms and their ...

  10. HTML+CSS知识点总结

    转自:http://blog.csdn.net/qiushi_1990/article/details/40260447?utm_source=tuicool&utm_medium=refer ...