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步是关键思考转折点,有点逆向思维的味道。暴力枚举也是可以很巧妙。没那么容易掌握好。

 #include <cstring>

 #include <iostream>

 #include <algorithm>

 #include <cstdio>

 #include <cmath>

 #include <map>

 #include <cstdlib>

 #define M(a,b) memset(a,b,sizeof(a))

 using namespace std;

 int res[];

 int main()

 {

   long long a,b,c;

   scanf("%I64d%I64d%I64d",&a,&b,&c);

   int count = ;

   for(int i = ;i<=;i++)

   {

       long long aa = ;

       for(int t = ;t<a;t++)

       {

           aa*=i;

       }

       if(b*aa+c>||b*aa+c<) continue;

       int tem = (int)(b*aa+c);

       int tem1 = tem;

       //cout<<i<<' '<<tem<<' ';

       if(tem<&&tem>)

       {

           int ans = ;

           while(tem)

           {

              ans += tem%;

              tem/=;

           }

           //cout<<ans<<endl;

           if(ans==i)

             res[count++] = tem1;

       }

   }

   printf("%d\n",count);

   for(int i = ;i<count;i++)

   {

       printf("%d ",res[i]);

   }

   if(count>)

     cout<<endl;

   return ;

 }

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. Ural 1011. Conductors

    1011. Conductors Time limit: 2.0 secondMemory limit: 64 MB Background Everyone making translations f ...

  2. 【原】移动web动画设计的一点心得——css3实现跑步

    今年3月份,由于公司业务需要,我转岗到微信产品部,离开了TID团队,人都是有感情的动物,更何况在一个团队呆了快 3 年,心中十分舍不得,鬼哥说了“天下没有不散的宴席...”,在我的世界里又多了一次离别 ...

  3. [ZZ]From QA to Engineering Productivity

    http://googletesting.blogspot.com/2016/03/from-qa-to-engineering-productivity.html In Google’s early ...

  4. 洛谷P1220关路灯[区间DP]

    题目描述 某一村庄在一条路线上安装了n盏路灯,每盏灯的功率有大有小(即同一段时间内消耗的电量有多有少).老张就住在这条路中间某一路灯旁,他有一项工作就是每天早上天亮时一盏一盏地关掉这些路灯. 为了给村 ...

  5. PHP对文件数据的存储和检索

    @(主要是对文件的操作) 文件处理:php操作文件主要是写入和读取这两种.执行的步骤都是一样的. 1.打开这个文件.如果打不开就先创建它.2.将数据写入这个文件,或者将数据读出这个文件.3.关闭文件. ...

  6. jquery的css详解(二)

    jq的工具方法style用于设置样式,jq的实例方法css在设置样式时就是调用的它,接下来分析一下源码. jQuery.extend({ ............................ st ...

  7. BZOJ1951[SDOI2010]古代猪文

    Description "在那山的那边海的那边有一群小肥猪.他们活泼又聪明,他们调皮又灵敏.他们自由自在生活在那绿色的大草坪,他们善良勇敢相互都关心--" --选自猪王国民歌 很久 ...

  8. 微信小程序之触控事件(四)

    [未经作者本人同意,请勿以任何形式转载] >>>什么是事件 事件是视图层到逻辑层的通讯方式. 事件可以将用户的行为反馈到逻辑层进行处理. 事件可以绑定在组件上,当达到触发事件,就会执 ...

  9. 生成 PDF 全攻略【2】在已有PDF上添加内容

    项目在变,需求在变,不变的永远是敲击键盘的程序员..... PDF 生成后,有时候需要在PDF上面添加一些其他的内容,比如文字,图片.... 经历几次失败的尝试,终于获取到了正确的代码书写方式. 在此 ...

  10. Dribbble for windows phone 8

    正如你看到文章的标题所示.这是一个Dribbble 基于windows phone 8的客户端.[开源项目] 对于大部分的开发人员来说很少关注Dribbble[不妨打开看看或是注册一个player账号 ...