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 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 这道题目比较好,想法,一开始不是我想的,枚举x很不现实, 1 ~ 1亿, 这样枚举肯定超时
而 s(x) 的范围就很明确, 1~81, 最多 999999999, 也就是9 个 9.所以就会用这个枚举。 枚举 s(x), 然后验证 是否是 x, 就这样
也模仿他人, 把那些能省事的宏定义写上,慢慢来吧
 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std;
#define LL long long
#define usLL unsigned LL
#define mz(array) memset(array, 0, sizeof(array))
#define minf(array) memset(array, 0x3f, sizeof(array)) LL bit_sum(LL x)
{
LL sum = ;
while(x)
{
sum += x % ;
x /= ;
}
return sum;
} LL powd(int t,int n){
LL sum=;
for(int i=;i<=n;i++)
sum*=t;
return sum;
} int main()
{
int a, b, c;
cin >> a >> b >> c;
int ans[];
int cnt = ;
for(int i = ; i <= ; i++)
{
LL t = powd(i, a);
LL x = t*b + c;
if(x > && x < && bit_sum(x)==i)
{
ans[cnt++] = x;
}
} printf("%d\n", cnt);
for(int i = ; i < cnt; i++)
{
printf("%d ", ans[i]);
}
puts("");
return ;
}

CodeForces460B. Little Dima and Equation的更多相关文章

  1. CF460B Little Dima and Equation (水题?

    Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...

  2. Codeforces Little Dima and Equation 数学题解

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

  3. B. Little Dima and Equation

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  4. cf B. Little Dima and Equation

    http://codeforces.com/contest/460/problem/B import java.util.*; import java.math.*; public class Mai ...

  5. codeforces 460B Little Dima and Equation 解题报告

    题目链接:http://codeforces.com/problemset/problem/460/B 题目意思:给出a, b, c三个数,要你找出所有在 1 ≤ x ≤ 1e9 范围内满足 x =  ...

  6. codeforces #262 DIV2 B题 Little Dima and Equation

    题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...

  7. Codeforces#262_1002

    Codeforces#262_1002 B. Little Dima and Equation time limit per test 1 second memory limit per test 2 ...

  8. Codeforces Round #262 (Div. 2) A B C

    题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...

  9. Codeforces Round #262 (Div. 2) 二分+贪心

    题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...

随机推荐

  1. struts2+hibernate 项目实战:图书管理系统

    经典项目,练手必备. 图书管理系统 需求分析(大致,并不专业):1.需要有用户管理: 1.1 用户注册: 1.2 用户登录: 1.3 用户信息修改: 1.4 用户修改密码: 2.需要有书本管理: 2. ...

  2. Linux的inode的理解

    文件名 -> inode -> device block 一.inode是什么? 理解inode,要从文件储存说起. 文件储存在硬盘上,硬盘的最小存储单位叫做"扇区"( ...

  3. [Unity3D]添加音效说明

    添加音效组件并添加音乐资源 其中Pitch用来提高和降低音调的,比如可以和赛车游戏的轮胎绑定,当轮胎越快,则音调越高 2D/3D音效:2D音效和摄影家的距离无关,可以看做是一个背景音乐:而3D音效则是 ...

  4. C C++ 语法

    非常酷的网站: http://yige.org/cpp/defined_data_types.php 在Linux下有一个目录/proc/$(pid),这个目录保存了进程号为pid的进程运行时的所有信 ...

  5. JS中数组Array的用法{转载}

    js数组元素的添加和删除一直比较迷惑,今天终于找到详细说明的资料了,先给个我测试的代码^-^var arr = new Array();arr[0] = "aaa";arr[1] ...

  6. codevs3163 抄书问题2

    题目描述 Description 现在要把M本有顺序的书分给K个人复制(抄写),每一个人的抄写速度都一样,一本书不允许给两个(或以上)的人抄写,分给每一个人的书,必须是连续的,比 如不能把第一.第三. ...

  7. 解决 PhpStorm 对 用单例模式实例化PHP类时,代码自动提示功能失效 的问题

    大部分PHP框架中,为了防止一个类被重复实例化,往往采用“单例模式”实例化类.我们的项目框架是这样做的: 先写好一个基类 /framework/Base.class.php,内容如下: <?ph ...

  8. Linux cp (复制)命令简介

    \cp  -rf  source1  source2   source3   ....   directory cp (复制档案或目录) [root@linux ~]# cp [-adfilprsu] ...

  9. 分布式中Redis实现Session终结篇

    上一篇使用Redis实现Session共享方式虽然可行,但是实际操作起来却很麻烦,现有代码已经是这个样子了,总不可能全部换掉吧!好吧,这是个很实际的问题,那么能不能实现无侵入式的分布式Session共 ...

  10. EXCEL科学计数法转为文本格式

    1.单元格格式-->特殊-->邮政编码 2.分列:选中数据-菜单栏“数据”-“分列”-下一步-下一步-选中文本-确定即可3.公式TEXT:如果数据在A列 =TEXT(A1,,0) 向下复制 ...