Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

이것저것

C언어 swea 1945 - 간단한 소인수분해 본문

Language/C언어

C언어 swea 1945 - 간단한 소인수분해

olivia-com 2020. 11. 20. 09:59

https://swexpertacademy.com/main/identity/anonymous/loginPage.do

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

#include <stdio.h>

int main(void){
	int test_case, num, i, j;
	int arr[5] = {2,3,5,7,11}; //배열 arr 선언 
	scanf("%d", &test_case);
	
	for(i = 0; i< test_case; i++){
		int cnt[5] = {0}; // 배열 cnt 초기화 
		scanf("%d", &num);
		
		for(j = 0; j < 5; j++){
			int count = 0;
			while(1){
				if(num % arr[j] == 0){ 
				// arr배열의 숫자 순서대로 나눠 떨어질때까지 개수 세기 
					count++;
					num /= arr[j];
					cnt[j] = count;
				}
				else{
					break;
				}
			}
		}
		printf("#%d ",i+1);
		int k;
		for(k = 0; k < 5; k++){
			printf("%d ", cnt[k]);
		}
		printf("\n");
	}
	return 0;
}

​