Skip to content

Instantly share code, notes, and snippets.

@chmllr
Last active December 31, 2015 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmllr/7934173 to your computer and use it in GitHub Desktop.
Save chmllr/7934173 to your computer and use it in GitHub Desktop.
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