public class Euler255 { static double totalcounts = 0; public static void main(String[] args) { long a = (long) Math.pow(10, 13); long b = (long) Math.pow(10, 14)-1; a = (long) Math.pow(10, 13); b = (long) Math.pow(10, 14)-1; long xzero = xzero((long) a); long time = System.currentTimeMillis(); count(a,b,1,xzero); System.out.println(totalcounts/(b-a+1)); System.out.println("Total Time :" + (System.currentTimeMillis()-time) + "ms"); } public static long numberOfIteration(long n) { long xk = xzero(n); long nextxk = nextxk(n, xk); int count = 1; while(xk!=nextxk) { xk = nextxk; nextxk = nextxk(n,xk); count++; } return count; } public static long xzero(long n) { long d = numberOfDigits(n); if (d%2 == 0) { return (long) (7*Math.pow(10, (d-2)/2)); } else { return (long) (2*Math.pow(10, (d-1)/2)); } } public static long numberOfDigits(long n) { long count=1; while (n/10>0) { count++; n=n/10; } return count; } public static long nextxk(long n, long xk) { double n1 = n; double toto = n1/xk; double tutu = Math.ceil(toto); double trtr = tutu + xk; double tata = trtr/2; double tktk = Math.floor(tata); long result = (long) tktk; return result; } public static void count(long a,long b,int iter, long xk) { long nexta = nextMultiple(a, xk); long nextxk = nextxk(a,xk); while (nexta