Codeforces Round #262 (Div. 2) B. Little Dima and Equation
2015-08-20 21:37
405 查看
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 functions(x) determines the sum of
all digits in the decimal representation of numberx.
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 printn integers in the increasing order — the solutions of the given equation. Print only integer solutions
that are larger than zero and strictly less than109.
Sample test(s)
Input
Output
Input
Output
Input
Output
大意:求X的各位和等于S(X)。
对公式分析。由于X的值<1e9所以,S(x)和最大为81即999999999.注意计算时不要超出数据给的范围。
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 functions(x) determines the sum of
all digits in the decimal representation of numberx.
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 printn integers in the increasing order — the solutions of the given equation. Print only integer solutions
that are larger than zero and strictly less than109.
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的各位和等于S(X)。
对公式分析。由于X的值<1e9所以,S(x)和最大为81即999999999.注意计算时不要超出数据给的范围。
#include<iostream> #include<cstring> #include<cstdio> #include<string> #include<cmath> #include<algorithm> #define LL __int64 #define inf 0x3f3f3f3f using namespace std; LL p[1000000]; int main() { LL n,m,i,j,k,x,y,pp; LL a,b,c; while(~scanf("%I64d %I64d %I64d",&a,&b,&c)) { y=0; for(i=1;i<=81;i++) { pp=1; for(j=1;j<=a;j++)//有些注成败的细节要注意,pow尽量少和整形数据运算容易数据丢失 pp*=i; x=b*pp+c; k=x; LL ans=0; while(x) { ans+=x%10; x/=10; } if(ans==i&&k>=1&&k<1e9)//注意运算结果在给定的范围内 { p[y++]=k; } } printf("%I64d\n",y);<span id="transmark"></span>//%I64d<span id="transmark"></span> for(i=0;i<y;i++) i==y-1?printf("%I64d\n",p[i]):printf("%I64d ",p[i]); } return 0; }
相关文章推荐
- 【机房收费系统】——上下机
- 微软发布 Windows Server 2016 预览版第三版,开发者要重点关注Nano Server
- python 引用ini配置文件
- 个人--理财经验001-2015.07.25
- 安卓理论之进程与线程
- Windows Server AppFabric Caching
- Python代码追踪(类似于bash -x的效果)
- const变量
- 设计模式之责任链模式(1)
- 图片懒加载方法
- Wormholes 3259 (最短路+判断负环是否存在)
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- 个人--在不同的城市里,年薪1万、10万、100万的人
- HYSBZ 1588 平衡树 splay第一题
- C++头文件与实现文件分别写什么
- App Widget
- HDU2795 Billboard(线段树基础题单节点更新区间查询)
- ArcEngine中License权限等级更改的问题
- XML与HTML
- hdu 5410 CRB and His Birthday 01背包和完全背包