알고리즘

[알고리즘] 백준 6679 - 싱기한 네자리 숫자 (C++)

blueberrysoda 2024. 12. 15. 23:35

[문제 링크] : https://www.acmicpc.net/problem/6679

#include <iostream> 
using namespace std;

int solve(int n, int t){
    int ret = 0;
    while(n != 0){
        ret += n % t;
        n /= t;
    }
    return ret;
}

int main(){
    for(int i=1000; i<10000; i++){
        int tmp = solve(i, 10);
        if(tmp == solve(i, 12) && tmp == solve(i, 16)){
            cout << i << "\n";
        }
    }
    return 0;
}