Little Gaurav and Sequence

  • + 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; 
    }