[BOJ] 분해합

마코레·2022년 7월 10일
0

코테공부

목록 보기
17/19
#include <iostream>
#include <cmath>
using namespace std;

void numfind(int N)
{
    int tmp = N;
    int start,i,sum,tmp2 = 0;
    for(i = -1; tmp; i++)
        tmp /= 10;
    start = round(pow(10,i)) - 9*i;
    tmp = start;
    while(1)
    {
        sum = tmp;
        tmp2 = tmp;
        while(tmp2)
        {
            sum += tmp2 % 10;
            tmp2 /= 10;
        }
        if(sum == N)
        {
            cout << tmp;
            return;
        }
        if(tmp == N)
        {
            cout << '0';
            return;
        }
        tmp++;
    }
}
int main() {
    int N;
    cin >> N;
    numfind(N);
}
  • 이 문제도 브루트 포스
  • 분해합이 n인 경우를 그냥 쭉 돌면서 찾는방식임.
profile
새싹 백엔드 개발자

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN