[java 백준] 실버 4/2331번 반복수열

[java 백준] 실버 4/2331번 반복수열

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45

import java.util. Scanner ; public class Main { public static int [][] arr; public static int [] visit; public static int count = 1 ; public static int lastCount = 0 ; public static void dfs( int x, int count, int p) { if (visit[x] = = 0 ) { visit[x] = count; String s = Integer. toString (x); int len = s. length (); int cnt = 0 ; for ( int j = 0 ; j < len; j + + ) { cnt + = Math.pow(Character.getNumericValue(s. charAt (j)), p); } count + + ; dfs(cnt, count, p); } else { lastCount = visit[x] - 1 ; return ; } } public static void main( String [] args) { Scanner sc = new Scanner ( System . in ); int num = sc.nextInt(); int p = sc.nextInt(); visit = new int [ 1000000 ]; dfs(num, count, p); System . out . println (lastCount); } } Colored by Color Scripter

from http://we1cometomeanings.tistory.com/157 by ccl(A) rewrite - 2021-09-26 13:01:06