Last active
December 31, 2015 04:29
-
-
Save chmllr/7934173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class HPYNOS { | |
public static void main(String[]args){ | |
Scanner s = new Scanner(System.in); | |
int[] cache = new int[800]; | |
int N = s.nextInt(); | |
int count = 0; | |
do { | |
N = breakIt(N); | |
if(cache[N] > 0) { | |
count = -1; | |
break; | |
} | |
cache[N] = 1; | |
count++; | |
} while(N != 1); | |
System.out.println(count); | |
} | |
private static int breakIt(int n) { | |
int s; | |
for(s = 0; n > 0; n /= 10) s += (n % 10) * (n % 10); | |
return s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment