슈콩

[SWEA] 제곱수 만들기 본문

Algorithms/SWEA

[SWEA] 제곱수 만들기

shukong 2025. 11. 15. 23:46

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXWXH_h695kDFAST

 

SW Expert Academy

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

swexpertacademy.com

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int n = Integer.parseInt(br.readLine());
			int result = 1;
			for(int i=2;i<=Math.sqrt(n);i++) {
				int cnt = 0;
				while(n%i==0) {
					n /= i;
					cnt++;
				}
				if(cnt%2!=0) {
					result *= i;
				}
			}
			if(n!=1) {
				result *= n;
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 유효숫자 표기  (0) 2025.11.16
[SWEA] 두 전구  (0) 2025.11.15
[SWEA] 구구단 걷기  (0) 2025.11.15
[SWEA] 공과 잡초  (0) 2025.11.15
[SWEA] 코딩 토너먼트1  (0) 2025.11.15