말랑한 하루

[SW Expert Academy] 1945 간단한 소인수분해 [C++] 본문

문제풀이/SWexpert Academy

[SW Expert Academy] 1945 간단한 소인수분해 [C++]

지수는말랑이 2021. 1. 20. 01:16
반응형

[ 핵심풀이 ]

[ 핵심소스 ]

[ C++ ]

#include <iostream>
#pragma warning(disable:4996)

using namespace std;

#define endl "\n"
#define MAX 5

int result[MAX];
int Div[MAX] = { 2,3,5,7,11 };

void solve(int item) {
    for (int i = 0; i < MAX; i++) {
        int cnt = 0;
        while (item % Div[i] == 0) {
            if (item == 0) break;
            item /= Div[i];
            cnt++;
        }
        result[i] = cnt;
    }
}
int main() {
    int tc;
    cin >> tc;

    for (int i = 1; i <= tc; i++) {
        int temp;
        cin >> temp;
        solve(temp);
        cout << "#" << i << " ";
        for (int k = 0; k < MAX; k++)
            cout << result[k] << " ";
        cout << endl;
    }
}
반응형
Comments