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 ...
随机推荐
- 你应该了解Nginx的7个原因
Nginx ("engine x")是一个高性能的HTTP和反向代理服务器,也是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器 1 负载均衡实 ...
- 帝国cms栏目自定义字段首页调用
例如:增加栏目自定义字段:chushi_bpic 用下面的灵动标签和调用: [e:loop={"select C.classid,C.classname,C.classimg,D.chush ...
- Aspx生命周期
今天去面试,碰到面试官问这个问题.aspx页面生命周期是什么?顿时懵逼 还跟我解释:就是页面怎么解析的aspx页面.果断没看过这方面知识,没答上来.现在记录一下 ASP.NET页面生命周期 ASP.N ...
- Mouse.OverrideCursor
介绍: 获取和设置整个应用程序的光标,WPF父元素将覆盖所有子元素的光标. WPF设置控件的光标: WPF 中每个光标通过一个System.Windows.Input.Cursor表示, 获取Curs ...
- Jboss7.1 加入realm auth认证 bootsfaces 美化的登录页面
jboss-as-7.1.1.Final\standalone\configuration: 1, standalone.xml中 <security-domains>标签里面添加: &l ...
- 什么是QName
看代码时经常碰到QName,当时对这个东东具体什么意思也是不太明白:今天在看SOAP消息的时候,想到这个东东,就去仔细看了下.QName其实就是Qualified Name的简称,在"Nam ...
- JS-鼠标经过显示二级菜单
在css处添加了border样式为了看得更清楚——源代码有一个程序漏洞,存在一个很烦人的大bug. <ul class="nav"> <li class=&quo ...
- BZOJ4590: [Shoi2015]自动刷题机
显然看着就是二分,仔细看的话显然刷的题数随n增大单调不升. 挂了一发是因为无解输出一个-1而不是两个…… #include<cstdio> #include<algorithm> ...
- netcat命令
1 简介 netcat是网络工具中的瑞士军刀,它能通过TCP和UDP在网络中读写数据.通过与其他工具结合和重定向,你可以在脚本中以多种方式使用它.使用netcat命令所能完成的事情令人惊讶. netc ...
- 斗鱼的sidebar的实现简陋的demo
斗鱼的sidebar的实现简陋的demo <!DOCTYPE html> <html> <head lang="en"> <meta ch ...