Sherlock and Square

Sort by

recency

|

6 Discussions

|

  • + 1 comment

    return (pow(2,n+1,1000000007)+2)%1000000007

  • + 0 comments

    My normal solution

    https://github.com/joy-mollick/Problem-Solving-Solutions-Math-Greedy-/blob/master/HackerRank-Sherlock%20and%20Square.cpp

  • + 0 comments

    the trick is to use a custom code for power generation

  • + 1 comment

    Is there any problem with the logic?

    #include <bits/stdc++.h>
    #define MOD 1000000007
    using namespace std; 
    
    int main(){
        int t; 
        cin>>t;
        for(int i=0;i<t;i++){
            long n; 
            cin>>n;
            cout<<2*fmod(1+pow(2,n),MOD)<<"\n";
        }
        return 0;
    }
    
  • [deleted]
    + 1 comment

    can anyone tell me why am I getting termination due to timeout for the following code

    test = int(input())
    
    for i in range(test):
        num = int(input())
        answer = (2**(num+1)) + 2
        print(answer % 1000000007)
    

    is there a way to do it even faster