B. Little Dima and Equation
来源:互联网 发布:淘宝卖家地址怎么看 编辑:程序博客网 时间:2024/05/22 03:38
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) ||||| (我第一次就是在这里出错的!!! 没有注意x的范围) of the equation:
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.
The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000; - 10000 ≤ c ≤ 10000).
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.
s(1000)=1
s(999999999)=81
思路出来的有木有! 1->81 枚举 s(x) 然后得到 x 再进行判断。
注意:1,x 在计算时的范围会超过 int 10000*81^5+10000;
2, x 也是有范围的 x (0 < x < 109)
//B#include<iostream>#include<cstdio>using namespace std;//---------------------------------int S(long long int x){ int ans=0; while(x>0) { ans+=x%10; x/=10; }return ans;}//--------------------------------long long int g(int x,int a){ int i;long long int ans=1; if(a==0) { ans=1; } else { for(i=1;i<=a;i++) { ans*=x; } }return ans;}//--------------------------------int main (){ int sx,i,a,b,c; long long int ans[100000],ans_num,x; while(~scanf("%d%d%d",&a,&b,&c)) { ans_num=0; for(sx=1;sx<=99;sx++) { x=b*g(sx,a)+c; if(sx==S(x)) {if(x>=1000000000) // 这里。。。。。;else{ans[ans_num]=x;ans_num++; } } else ; } if(ans_num==0) cout<<0<<endl; else { cout<<ans_num<<endl; for(i=0;i<ans_num;i++) //printf("%I64d ",ans[i]); cout<<ans[i]<<" ";printf("\n"); } }return 0;}
- B. Little Dima and Equation
- B. Little Dima and Equation
- B. Little Dima and Equation
- B. Little Dima and Equation
- CF 460B Little Dima and Equation
- codeforces-#460B Little Dima and Equation
- codeforce 460B Little Dima and Equation
- 460B. Little Dima and Equation
- [Codeforces] 460B - Little Dima and Equation
- Codeforces 460B Little Dima and Equation
- 460 B. Little Dima and Equation
- CF 460B .Little Dima and Equation
- CF 460B Little Dima and Equation
- codeforces #262 DIV2 B题 Little Dima and Equation
- Codeforces Round #262 (Div. 2)B. Little Dima and Equation
- Codeforces Round #262(div2) B. Little Dima and Equation
- Codeforces Round #262 (Div. 2) B. Little Dima and Equation
- Codeforces 460B Little Dima and Equation(暴力)
- POJ3356 AGTC DP
- ImageView的使用,实现本地图片的适屏显示和裁剪功能。
- Linux Shell 通配符、元字符、转义符使用实例介绍
- linux基本分区命令和制作超过4G的启动盘
- 几种数据存储结构详解
- B. Little Dima and Equation
- 修改UITextfield的Placeholder字体的颜色
- 460 B. Little Dima and Equation
- [小技巧] diff 在比较两个目录时忽略 .svn 目录
- Linux下可执行文件格式详解
- mysql 、oracle、sqlserver获取最近一次插入记录
- 重叠I/O模型分析
- Program Block-systemverilog
- Linux在后台运行jar程序