Little Gaurav and Sequence

Sort by

recency

|

6 Discussions

|

  • + 3 comments

    This is a pure math problem. You don't need to do any coding! Approach this like a math problem and solve it on paper then put your result in code.

    My code:

    def solve(n):
        if(n%2==1):
            return(0)
        ln=math.floor(math.log2(n))
        if(ln==0):
            return(2)
        return([0, 6, 2, 8, 4][ln%5])
    
  • + 0 comments

    JavaScript solution:

    function solve(n) {
        if (n % 2) return 0;
        let i_max = Math.floor(Math.log2(n));
        let res = 0;
        for (let i = 0; i <= i_max; i++) {
            res += [6, 2, 4, 8][(2 ** i + 2 * n) % 4];
        }
        return res%10; 
    }
    
  • + 0 comments

    int main(){ long long int t,n,p; scanf("%lld",&t); while(t--){ scanf("%lld",&n); if(n%2!=0){ printf("0\n"); }else if(n==2){ printf("6\n"); } else{ p=log(n)/log(2); printf("%lld\n",(p*6)%10); } } }

  • + 2 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);
            }
            
        }
    }
    
  • + 0 comments

    I am not sure if this problem is correct. The output is not mine. Even when I deleted all the print (I am using Python), the outputs never change.