CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B
|
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 Input
1 2 -18 Output
0 Input
2 2 -1 Output
4 |
题意:给出一个公式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 (水题?的更多相关文章
- fzu 1909 An Equation(水题)
题目链接:fzu 1909 An Equation 典型的签到题. #include <stdio.h> #include <string.h> bool judge(int ...
- B - 楼下水题(扩展欧几里德)
B - 楼下水题 Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- [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 ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
- BZOJ 1303 CQOI2009 中位数图 水题
1303: [CQOI2009]中位数图 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 2340 Solved: 1464[Submit][Statu ...
随机推荐
- O(nlogn)LIS及LCS算法
morestep学长出题,考验我们,第二题裸题但是数据范围令人无奈,考试失利之后,刻意去学习了下优化的算法 一.O(nlogn)的LIS(最长上升子序列) 设当前已经求出的最长上升子序列长度为len. ...
- css中margin-top/margin-bottom失效
要设置这两个值,我的理解应该在这个div的父容器中设置了固定宽高,或者设置了绝对定位,比如position:absolute(绝对定位) 或者压根不用,直接用padding-top/padding-b ...
- CMMI3标准文档模板大全
链接:http://pan.baidu.com/s/1c2cGX8W 密码:ulns
- Android成长日记-ProgressBar的设计
ProgressBar的关键属性 Android:max=”100” - ---最大显示进度 Android:progress=”50”----第一显示进度 Android:secondaryProg ...
- 【问题】R文件报错原因及解决办法 (转)
错误如图.下面是几种解决方法(网上搜集的). 1.如果是导入项目出现这个问题,一般是R文件没有更新造成(据说导入项目,R不会自动更新).可以Project——clean以下,R文件会重新生成. 2.选 ...
- 分布式ID生成器
最近会写一篇分布式的ID生成器的文章,先占位.借鉴Mongodb的ObjectId的生成: 4byte时间戳 + 3byte机器标识 + 2byte PID + 3byte自增id 简单代码: imp ...
- 为什么要用Markdown写东西
为什么要用Markdown 不用费心去调格式了,比方说题目加粗什么的,删除线什么的,代码也只要四个空格就好了~ 学起来很简单,几乎没什么学习成本,而收益却很大 这几乎快让我我想从cnblog转到简书了 ...
- jQuery知识点总结(第五天)
节点的操作和数据库操作一样,无非是增.删.改.查. 今天总结删除节点.复制节点.替换节点.与包裹节点 删除节点: 如果文档中一个元素多余,那么就需要删除掉.jQuery提供了三种删除节点的方法.分别是 ...
- vmware的安装
VMware Workstation是一款功能强大的虚拟机软件,在不影响本机操作系统的情况下,用户可以在虚拟机中同时运行不同版本的操作系统,用于开发.测试以及部署工作,这边小编为大家分享最新版本VMw ...
- Servlet Request的 getInputStream() getReader() getParameter()
如果你知道了这三者的区别,请忽略 最近碰到了servlet对入参获取方式的处理问题,因为二方库处理不当,导致了获取不到入参的情况,之前也知道这三个方法不兼容,现简单介绍下 1.这三个获取入参的方法,是 ...