Sort by

recency

|

207 Discussions

|

  • + 0 comments

    **long lights(int n) { long ways = 1; for(int i = 0 ; i < n ; i++){ ways *= 2; if(ways > 100000) ways %= 100000; } return ways-1;

  • + 0 comments

    The problem here is big integers We would not use big integers if we apply modular ariphmetics (A*B) mod M = (A mod M * B mod M) mod M

    https://www.geeksforgeeks.org/modular-multiplication/ https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/modular-multiplication

    my solution:

    https://github.com/Tusenka/hackerrank/blob/main/bulbs.py

  • + 0 comments

    Python Solution: def lights(n): # Write your code here if n==1: return 1 else: return ((2**n-1)%10**5)

  • + 0 comments

    Draw out the truth table for N inputs and you will see that there is one input where all the values are 0. The rest of the inputs has at least one set bit. that means the answer is (2 ^ N) - 1 and then take the modulus of it.

  • + 0 comments

    Here's my java solution:

    public static long lights(int n) {

        BigInteger ans=(BigInteger.valueOf(2).pow(n).subtract(BigInteger.valueOf(1))).mod(BigInteger.TEN.pow(5));  
    
        return ans.longValue();
    }