CodeForces460B. Little Dima and Equation
1 second
256 megabytes
standard input
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.
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 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.
3 2 8
3
10 2008 13726
1 2 -18
0
2 2 -1
4
1 31 337 967 这道题目比较好,想法,一开始不是我想的,枚举x很不现实, 1 ~ 1亿, 这样枚举肯定超时
而 s(x) 的范围就很明确, 1~81, 最多 999999999, 也就是9 个 9.所以就会用这个枚举。 枚举 s(x), 然后验证 是否是 x, 就这样
也模仿他人, 把那些能省事的宏定义写上,慢慢来吧
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> 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)) LL bit_sum(LL x)
{
LL sum = ;
while(x)
{
sum += x % ;
x /= ;
}
return sum;
} LL powd(int t,int n){
LL sum=;
for(int i=;i<=n;i++)
sum*=t;
return sum;
} int main()
{
int a, b, c;
cin >> a >> b >> c;
int ans[];
int cnt = ;
for(int i = ; i <= ; i++)
{
LL t = powd(i, a);
LL x = t*b + c;
if(x > && x < && bit_sum(x)==i)
{
ans[cnt++] = x;
}
} printf("%d\n", cnt);
for(int i = ; i < cnt; i++)
{
printf("%d ", ans[i]);
}
puts("");
return ;
}
CodeForces460B. Little Dima and Equation的更多相关文章
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Codeforces Little Dima and Equation 数学题解
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- B. Little Dima and Equation
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- cf B. Little Dima and Equation
http://codeforces.com/contest/460/problem/B import java.util.*; import java.math.*; public class Mai ...
- codeforces 460B Little Dima and Equation 解题报告
题目链接:http://codeforces.com/problemset/problem/460/B 题目意思:给出a, b, c三个数,要你找出所有在 1 ≤ x ≤ 1e9 范围内满足 x = ...
- codeforces #262 DIV2 B题 Little Dima and Equation
题目地址:http://codeforces.com/contest/460/problem/B 这题乍一看没思路.可是细致分析下会发现,s(x)是一个从1到81的数,不管x是多少.所以能够枚举1到8 ...
- Codeforces#262_1002
Codeforces#262_1002 B. Little Dima and Equation time limit per test 1 second memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) A B C
题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...
- Codeforces Round #262 (Div. 2) 二分+贪心
题目链接 B Little Dima and Equation 题意:给a, b,c 给一个公式,s(x)为x的各个位上的数字和,求有多少个x. 分析:直接枚举x肯定超时,会发现s(x)范围只有只有1 ...
随机推荐
- entity
- JVM垃圾回收算法
- Apache Shiro 学习记录1
最近几天在学习Apache Shiro......看了一些大神们的教程.....感觉收获不少.....但是毕竟教程也只是指引一下方向....即使是精品教程,仍然有很多东西都没有说明....所以自己也稍 ...
- NOIP2009 Hankson的趣味题
题目描述 Description Hanks 博士是BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫Hankson.现在,刚刚放学回家的Hankson 正在思考一个有趣的问题.今天在 ...
- jQuery如何退出each循环的?
试问:jQuery是如何退出each循环的? 在回调函数里return false即可,大多数jQuery的方法都是如此的. 返回 'false' , 将停止循环 (就像在普通的循环中使用 'bre ...
- JavaScript对象的理解 及 字面量对象与数组的关系
JavaScript的简单类型包括 数字.字符串.布尔值.null值.undefined值. 其他的值都是对象.对象是可变的键控集合.数组.函数.正则表达式都是对象. 对象是属性的容器,属性都是名字和 ...
- Linux文件(区域)锁函数 -- open()、fcntl()
一.什么是文件锁定 对于锁这个字,大家一定不会陌生,因为我们生活中就存在着大量的锁,它们各个方面发挥着它的作用,现在世界中的锁的功能都可归结为一句话,就是阻止某些人做某些事,例如,门锁就是阻止除了屋主 ...
- MVC项目使用easyui的filebox控件上传文件
开发环境:WIN10+IE11,浏览器请使用IE10或以上版本 开发技术框架MVC4+JQuery Easyui+knockoutjs 效果为弹出小窗体,如下图 1.前端cshtml文件代码(只包含文 ...
- SQLite返回码
SQLite返回码 返回码含义 宏 值 含义 SQLITE_OK 0 返回成功 SQLITE_ERROR 1 SQL错误或数据库不存在 SQLITE_INTERNAL 2 SQLite内部逻辑错误 S ...
- Linux From Scratch - Version 7.7-systemd (中文)
Linux From Scratch - Version 7.7-systemd: https://linux.cn/lfs/LFS-BOOK-7.7-systemd/index.html