Codeforces 875A Classroom Watch 문제 해결
3297 단어 잡다한 문제
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.
Input The first line contains integer n (1 ≤ n ≤ 109).
Output 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.
Examples input 21 output 1 15 input 20 output 0 Note 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을 주고 x에 x의 각 위치의 합이 n과 같은 숫자의 개수를 구하여 x를 출력한다.
가령 x가len의 자릿수라고 가정하면 x에 x의 각 자릿수와 n의 차이는 반드시len*9을 초과하지 않을 것이다. 폭력은 적당한 범위 내에서 한 번 훑어본다.
#include
using namespace std;
int n;
vector <int> a;
bool check(int x) {
int s = x;
for(int i = 1; x; i++) s += x%10, x /= 10;
if(s == n) return 1;
return 0;
}
int main() {
scanf("%d",&n);
for(int i = (n-100 > 0) ? n-100 : 0; i <= n; i++) {
if(check(i)) a.push_back(i);
}
printf("%d",a.size());
for(int i = 0; i < a.size(); i++) printf("
%d",a[i]);
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단한 동적 계획-포장 문제포장 문제 상자의 용적이 얼마인지 알려주고, N개의 물건과 각 물건의 부피가 있는지 알려주며, 물건을 어떻게 선택해야 상자의 남은 용적을 최소화할 수 있는지 물어본다.검색 반복 기억화 검색 동적 기획...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.