Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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 31
Tags
more
Archives
Today
Total
관리 메뉴

자이의 프로그래밍

SWEA-1945 간단한 소인수분해 본문

Algorithm/Cases-Study

SWEA-1945 간단한 소인수분해

Xi_kor 2021. 3. 18. 20:33

2로 나눠지는 한 2로 계속 나누고 3으로 나눠지는 한 3으로 계속 나누는 과정을 반복한 뒤에 각각을 출력했다.

#include<iostream>

using namespace std;

int main(int argc, char** argv)
{
	int test_case;
	int T;
	cin>>T;
	for(test_case = 1; test_case <= T; ++test_case)
	{
		int twonum=0;
		int threenum=0;
		int fivenum=0;
		int sevennum=0;
		int elevennum=0;
		
		int a;
		cin>>a;
		
		while(a%2==0){
			a=a/2;
			twonum++;
		}
		
		while(a%3==0){
			a=a/3;
			threenum++;
		}
		
		while(a%5==0){
			a=a/5;
			fivenum++;
		}
		
		while(a%7==0){
			a=a/7;
			sevennum++;
		}
		
		while(a%11==0){
			a=a/11;
			elevennum++;
		}
		
		cout<<"#"<<test_case<<" "<<twonum<<" "<<threenum<<" "<<fivenum<<" "<<sevennum<<" "<<elevennum<<'\n';
	}
	return 0;//정상종료시 반드시 0을 리턴해야합니다.
}

'Algorithm > Cases-Study' 카테고리의 다른 글

SWEA-1213 String  (0) 2021.03.25
SWEA-1940 가랏! RC카!  (0) 2021.03.18
SWEA-1946 간단한 압축풀기  (0) 2021.03.18
SWEA-1948 날짜 계산기  (0) 2021.03.18
SWEA-1954 달팽이 숫자  (0) 2021.03.18