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 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 test(s)
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

题目地址:http://codeforces.com/contest/460/problem/B

这题乍一看没思路,但是仔细分析下会发现,s(x)是一个从1到81的数,无论x是多少。所以可以枚举1到81,这样就转化成了一个一元一次方程,直接求解x就可以了。这时候还要判断x是否在1到10^9之间,并且它的各位数之和是s(x)。

这题脑残了两次。。。第一次是写成了<=10^9。。然后发现错误后,就又改了回来。。但是发现10^9是不可能的

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <algorithm>
#include <queue>
using namespace std;
#define LL __int64
LL aa[100];
int main()
{
LL n, a, b, c, ans=0, i, y, zz, j;
LL x, z;
scanf("%I64d%I64d%I64d",&a,&b,&c);
for(i=1;i<=81;i++)
{
zz=1;
for(j=1;j<=a;j++)
zz*=i;
x=zz*b+c;
y=0;
z=x;
while(z)
{
y+=z%10;
z/=10;
}
if(y==i&&x>=1&&x<1e9)
{
aa[ans++]=x;
}
}
printf("%I64d\n",ans);
for(i=0;i<ans;i++)
{
printf("%I64d ",aa[i]);
}
return 0;
}

最新文章

  1. MySQL运行状态show status详解
  2. 一种简单的实现:Android一键换肤功能
  3. 关于转换大写中文金额-新学的java函数整理
  4. SynchronousQueue 的简单应用
  5. VBS数组
  6. php增加对mysqli的支持
  7. WOSA协议(转)
  8. php 在线 mysql 大数据导入程序
  9. POJ 1459 Power Network(网络最大流,dinic算法模板题)
  10. 终于等到你!MobileTest免费公测,华为带你走出安卓适配大坑
  11. sklearn:最近邻搜索sklearn.neighbors
  12. Zookeeper管理多个HBase集群
  13. Spring-Security-OAuth2调用微信API
  14. 实现Linux下od -tx -tc XXX的功能
  15. nginx-添加禁止访问规则
  16. docker删除名字为none的imgae
  17. maven的动态打包功能
  18. day39Python
  19. C语言复习---打印菱形
  20. PHP-FPM子进程过少解决办法

热门文章

  1. container_of
  2. Hard-Margin SVM(支持向量机)
  3. 【成都GamEver游戏公司诚邀服务器伙伴】【7~15k一年4次项目奖金】
  4. Windows7 32位下opencv与python2.66的环境配置
  5. Apache Rewrite常用设置说明
  6. 王家林的81门一站式云计算分布式大数据&amp;移动互联网解决方案课程第14门课程:Android软硬整合设计与框架揭秘: HAL&amp;Framework &amp;Native Service &amp;App&amp;HTML5架构设计与实战开发
  7. C#正则表达式判断字符串是否是金钱
  8. C++中#include包含头文件带 .h 和不带 .h 的区别
  9. AutoCAD.NET二次开发:创建自定义菜单(AcCui)
  10. HDU 3308 LCIS (线段树区间合并)