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.
To be honest, i didnt know how to handle the "int" output in Java, so i have changed it.
classResult{/* * Complete the 'fibonacciModified' function below. * * The function is expected to return an INTEGER. * The function accepts following parameters: * 1. INTEGER t1 * 2. INTEGER t2 * 3. INTEGER n */publicstaticBigIntegerfibonacciModified(intt1,intt2,intn){// Write your code hereBigInteger[]b=newBigInteger[n+1];b[1]=BigInteger.valueOf(t1);b[2]=BigInteger.valueOf(t2);for(inti=3;i<=n;i++){b[i]=b[i-1].multiply(b[i-1]).add(b[i-2]);}returnb[n];}}publicclassSolution{publicstaticvoidmain(String[]args)throwsIOException{BufferedReaderbufferedReader=newBufferedReader(newInputStreamReader(System.in));BufferedWriterbufferedWriter=newBufferedWriter(newFileWriter(System.getenv("OUTPUT_PATH")));String[]firstMultipleInput=bufferedReader.readLine().replaceAll("\\s+$","").split(" ");intt1=Integer.parseInt(firstMultipleInput[0]);intt2=Integer.parseInt(firstMultipleInput[1]);intn=Integer.parseInt(firstMultipleInput[2]);BigIntegerresult=Result.fibonacciModified(t1,t2,n);bufferedWriter.write(result.toString());bufferedWriter.newLine();bufferedReader.close();bufferedWriter.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fibonacci Modified
You are viewing a single comment's thread. Return to all comments →
To be honest, i didnt know how to handle the "int" output in Java, so i have changed it.