We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;importjava.math.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannerscanner=newScanner(System.in);intN=scanner.nextInt();scanner.close();List<Integer>iterations=newArrayList<>();BigIntegernumerator=BigInteger.valueOf(3);BigIntegerdenominator=BigInteger.valueOf(2);for(inti=2;i<=N;i++){BigIntegernewNumerator=numerator.add(denominator.multiply(BigInteger.valueOf(2)));BigIntegernewDenominator=numerator.add(denominator);if(newNumerator.toString().length()>newDenominator.toString().length()){iterations.add(i);}numerator=newNumerator;denominator=newDenominator;}for(intiteration:iterations){System.out.println(iteration);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #57: Square root convergents
You are viewing a single comment's thread. Return to all comments →
JAva Code