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 ...
随机推荐
- 【poj1987】 Distance Statistics
http://poj.org/problem?id=1987 (题目链接) 题意 给出一棵树,求树上距离不超过K的点对个数. Solution 点分治,同poj1741. 代码 // poj1987 ...
- GitHub Pages和每个项目绑定自定义域名(支持多个和顶级域名)
假设我购买的域名为www.easonjim.com,想把www.easonjim.com和easonjim.com的域名跳转到下面的网址easonjim.github.io. 而我在github上的账 ...
- yocto系统介绍
The Yocto Project is an open source collaboration project that provides templates, tools and methods ...
- Pipe
#一边压缩一边传 一边解压 到对方的目录为/tlj/2/ / | ssh root@172.16.200.56 tar xzf - -C /tlj #在一个需要文件名的地方 使用-重定向输出到stdo ...
- css3 media媒体查询器用法总结
随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得在国内IE6用户居高不下的情况下,这些新的技术还不会广泛的蔓延下去,那你就错了,如今淘宝,凡客,携程等等公司都已经在大胆 ...
- UVa 7146 Defeat the Enemy(贪心)
题目链接: 传送门 Defeat the Enemy Time Limit: 3000MS Memory Limit: 32768 KB Description Long long ago t ...
- Linux之:Ubuntu速学笔记(2)
撰写日期:2016-7-3 18:20:39 基本内容包括:Flash player安装.编译安装PHP.写个简单的PHP程序:Java程序(Java需要使用“javac”命令编译一下才能执行) 一. ...
- Negative log-likelihood function
Softmax function Softmax 函数 \(y=[y_1,\cdots,y_m]\) 定义如下: \[y_i=\frac{exp(z_i)}{\sum\limits_{j=1}^m{e ...
- [USACO 2010 OPEN]SLIED
传送门 这道题的题意描述简直有毒.题没看完一眼分层图,然后火速敲了个堆优化的dijkstra,然后就被样例教做人了QAQ 这里说的最坏的情况让我很迷茫?感觉很难判定到底什么是最坏的情况以及确定了最坏的 ...
- Nginx系列5之让Nginx支持HTTP1.1
preface nginx在反向代理HTTP协议的时候,默认使用的是HTTP1.0去向后端服务器获取响应的内容后在返回给客户端. HTTP1.0和HTTP1.1的一个不同之处就是,HTTP1.0不支持 ...