You are viewing a single comment's thread. Return to all comments →
O(1) :)
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in=new Scanner(System.in); int t=in.nextInt(); for(int a0=0;a0<t;a0++){ long n=in.nextLong(); double x=Math.log(n)/Math.log(2); int y=(int)x+1; int s=0; if(y==1) s=2; else s=(y-1)*6; int a=s%10; int b=5; if(n%2==0) b=1; int c=(a*b)%10; System.out.println(c); } } }
Can yoy please explain the logic to get this logic?
Open the editor they gave a very nice solution to it on the basis of above code
Nice solution, but it is actually O(log(n)), as computing the log(n) takes O(log(n)) time.
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Little Gaurav and Sequence
You are viewing a single comment's thread. Return to all comments →
O(1) :)
Can yoy please explain the logic to get this logic?
Open the editor they gave a very nice solution to it on the basis of above code
Nice solution, but it is actually O(log(n)), as computing the log(n) takes O(log(n)) time.