import java.util.Scanner;
public class Solution {
	static int N,len;
	static int[] arr;
	static boolean[] check;
	static boolean result;
 	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		
		int T;
		T=Integer.parseInt(sc.nextLine());
		
		StringBuilder sb = new StringBuilder();
		for(int test_case = 1; test_case <= T; test_case++)
		{
			String s = sc.nextLine();
			
			N = Integer.parseInt(s);
			
			result = false;
			
			len = s.length();
			arr = new int[len];
			check = new boolean[len];
			
			for(int i=0; i<s.length(); i++) {
				arr[i]=s.charAt(i)-'0';
			}
			
			make("",0);
			
			sb.append("#"+test_case+" "+ (result ? "possible":"impossible")).append('\n');
		}
		
		System.out.println(sb);
	}
 	
 	static void make(String s,int count) { 
 		
 		if(result== true) return;
 		
 		if(count==len) {
 			int temp = Integer.parseInt(s);
 			if(s.charAt(0)-'0'!=0 && temp>N && temp%N==0) {
 				result=true;
 			}
 			return;
 		}
 		
 		for(int i=0; i<len; i++) {
			if(check[i]==false) {
				check[i]=true;
				make(s+Integer.toString(arr[i]),count+1);
				check[i]=false;
			}
		}
 	}
}

기본중의 기본이자나여~

꼭 다시풀어보기~ 잊쥐뫄

 

밤에 풀다가 잤다,, 아침에 산뜻한 시작 🤩

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

9778. 카드 게임 - d3  (0) 2022.06.10
7102. 준홍이의 카드놀이 - d3  (0) 2022.06.10
9480. 민정이와 광직이의 알파벳 공부 - d3  (0) 2022.06.09
8016. 홀수 피라미드 - d3  (0) 2022.06.06
9940. 순열1 - d3  (0) 2022.06.04

+ Recent posts