Codeforces C. Classroom Watch
1 second
512 megabytes
standard input
standard output
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number xwritten in decimal numeral system.
Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.
The first line contains integer n (1 ≤ n ≤ 109).
In the first line print one integer k — number of different values of x satisfying the condition.
In next k lines print these values in ascending order.
21
1
15
20
0
In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such x.
从n-n的位数*9到n枚举就行了;
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std; int n,ans[],res,k; int main(){
scanf("%d",&n);
long long g=,gg=;
while(g<=n){
g=g*+;
gg++;
}
gg+=;
for(int i=n-gg*;i<=n;i++){
int x=n-i,a=i;
while(a>){
x=x-a%;
a=a/;
}
if(x==){
res++;
ans[res]=i;
}
}
printf("%d\n",res);
for(int i=;i<=res;i++)
printf("%d\n",ans[i]);
}
Codeforces C. Classroom Watch的更多相关文章
- Codeforces 876C Classroom Watch:枚举
题目链接:http://codeforces.com/contest/876/problem/C 题意: 定义函数:f(x) = x + 十进制下x各位上的数字之和 给你f(x)的值(f(x) < ...
- CodeForces - 876C Classroom Watch (枚举)
题意:已知n,问满足条件"x的各个数字之和+x=n"的x有几个并按升序输出. 分析: 1.n最大1e9,10位数,假设每一位都为9的话,可知x的各个数字之和最大可以贡献90. 2. ...
- codeforces 876 C. Classroom Watch
http://codeforces.com/contest/876/problem/C C. Classroom Watch time limit per test 1 second memory l ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom
链接:https://codeforces.com/contest/1166/problem/A 题意: There are nn students in the first grade of Nlo ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch
http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...
- Codeforces 1166A - Silent Classroom
题目链接:http://codeforces.com/problemset/problem/1166/A 思路:统计所有首字母出现的次数,由贪心可知对半分最少. AC代码: #include<i ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)
A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- codeforces Round #441 C Classroom Watch【枚举/注意起点】
C. time limit per test 1 second memory limit per test 512 megabytes input standard input output stan ...
- 「Codeforces Round #441」 Classroom Watch
Discription Eighth-grader Vova is on duty today in the class. After classes, he went into the office ...
随机推荐
- 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...
- Vue入门
一.引入vue 方法一:下载vue.js,然后像引用jquery一样,在HTML中使用script标签引入 <script src="https://unpkg.com/vue/dis ...
- [Link-Cut-Tree]【学习笔记】
可以按照<Utopiosphere>的调唱出来 “Link-Cut ,Time doesn’t stop .Prepare your doubts ,Eat them up” 参考资料: ...
- HUST 1555 A Math Homework
1555 - A Math Homework 时间限制:1秒 内存限制:128兆 338 次提交 131 次通过 题目描述 QKL is a poor and busy guy, and he ...
- HDU1728-逃离迷宫-BFS
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- [国嵌攻略][148][MTD系统架构]
MTD设备概述 Flash在嵌入式系统中是必不可少的,它是bootloader.Linux内核和文件系统的最佳载体.在Linux内核中引入了MTD子系统为NOR Flash和Nand FLash设备提 ...
- 狗书无敌,天下第一(flask基础)
为什么选择使用flask? 和其他框架相比, Flask 之所以能脱颖而出,原因在于它让开发者做主,使其能对程序具有全面的创意控制. 在 Flask 中,你可以自主选择程序的组件,如果找不到合适的,还 ...
- JS URI Encode
javascript中存在几种对URL字符串进行编码的方法:escape/encodeURI/encodeURIComponent.这几种编码所起的作用各不相同. escape 采用ISO Latin ...
- 详解String类中的intern()方法
我们用一个经典的例子来理解 package com.jvm.heap; public class MyTest { public static void main(String[] args) { S ...
- C++异常层次结构
#define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; class MyArray { publi ...