ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 27번
    인프런 알고리즘테스트 문제 2020. 9. 2. 14:36
    #include<iostream>
    #include<vector>
    
    using namespace std;
    int main() {
    	int N = 0;
    	int tmp = 0;
    	int j=0;
    	cin >> N;
    	vector<int> arr(N + 1);
    	for (int i = 0; i <= N; i++)
    	{
    		arr[i] = 0;
    	}
    	for (int i = 2; i <= N; i++)
    	{
    		tmp = i;
    		j = 2;
    		while (1)
    		{
    			if (tmp%j == 0)
    			{
    				tmp = tmp / j;
    				arr[j]++;
    			}
    			else if (tmp == 1)
    			{
    				break;
    			}
    			else j++;
    			
    		}
    		
    	}
    	cout << N << "!" << "=";
    	for (int i = 0; i <= N; i++)
    	{
    		if (arr[i] != 0)
    		{
    			cout << arr[i] << " ";
    		}
    	}
    }

    '인프런 알고리즘테스트 문제' 카테고리의 다른 글

    29번  (0) 2020.09.02
    28번  (0) 2020.09.02
    26번  (0) 2020.08.31
    25번  (0) 2020.08.31
    24번  (0) 2020.08.31
Designed by Tistory.