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
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 = 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……血的教训

代码:

 //#pragma comment(linker, "/STACK:102400000,102400000")
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
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))
#define REP(i,n) for(i=0;i<(n);i++)
#define FOR(i,x,n) for(i=(x);i<=(n);i++)
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define WN(x) prllf("%d\n",x);
#define RE freopen("D.in","r",stdin)
#define WE freopen("1biao.out","w",stdout)
#define mp make_pair
#define pb push_back
vector<int>v;
int a,b,c;
int main(){
int i,j;
ll k;
scanf("%d%d%d",&a,&b,&c);
v.clear();
for(i=;i<=;i++){
k=;
REP(j,a)k*=i;
ll x=k*b+c;
if(x<= || x>=)continue;
int y=x,sum=;
while(y){
sum+=y%;
y/=;
}
if(sum==i)v.pb(x);
}
int maxi=v.size();
printf("%d\n",maxi);
if(maxi>)printf("%d",v[]);
for(i=;i<maxi;i++)
printf(" %d",v[i]);
return ;
}

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. npm下载包时代理配置

    主要有两种方式,1通过命令行临时配置,2通过配置文件进行永久配置. 1.命令行: npm install --proxy http://localhost:1080 如果有账号密码等验证的,需要在后面 ...

  2. 洛谷P3398 仓鼠找sugar

    题目描述 小仓鼠的和他的基(mei)友(zi)sugar住在地下洞穴中,每个节点的编号为1~n.地下洞穴是一个树形结构.这一天小仓鼠打算从从他的卧室(a)到餐厅(b),而他的基友同时要从他的卧室(c) ...

  3. 良精南方cms /inc/Check_Sql.asp SQL Injection Based On Cookie

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Relevant Link:2. 漏洞触发条件 0x1: POC usi ...

  4. C#获取外网IP

    思路是通过WebRequest连接一些网上提供IP查询服务的网站,下载到含有你的IP的网页,然后用正则表达式提取出IP来 class Program { static void Main(string ...

  5. iOS - 落叶加载动画效果

    代码下载地址:https://github.com/nLoser/LeafLoadingView 效果: 说明:效果是在网上看到的,并且自己按照效果自己实现,树叶使用CAEmitterLayer做的, ...

  6. BZOJ1915: [Usaco2010 Open]奶牛的跳格子游戏

    权限题,没有传送门. 这很显然是一道DP题,刚看完题目可能会比较懵逼.这道题如果不要求回去,那么就是一道很裸的DP题.但是本题要求回去而且回去的格子的前一个格必须是之前经过的. 先不考虑回去的路程,对 ...

  7. C#------如何取出exe运行文件给客户使用

    1.将解决方案配置里面的“Debug”转换成“Release” 2.右击“解决方案”,选着“重新生成解决方案”,以得到最新的版本 3.找到工程目录下的“bin”文件夹,里面有“Release”文件夹, ...

  8. 自然语言15_Part of Speech Tagging with NLTK

    https://www.pythonprogramming.net/part-of-speech-tagging-nltk-tutorial/?completed=/stemming-nltk-tut ...

  9. N-Gram

    N-Gram是大词汇连续语音识别中常用的一种语言模型,对中文而言,我们称之为汉语语言模型(CLM, Chinese Language Model).   中文名 汉语语言模型 外文名 N-Gram 定 ...

  10. centos6.5编译安装git

    1.下载高版本的git,地址:https://github.com/git/git/release,选择git-2.9.3.tar.gz 2.安装依赖包.解压.编译安装 yum install cur ...