Optimal_Aces's blog

By Optimal_Aces, history, 5 years ago, In English

https://www.codechef.com/problems/CKISSHUG

My method :- if first place is H then there are 2^(n-1) possibilities if first place is K then there are 2^(n-1/2) possibilities but this method is not right .

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I fully solved it on Codechef.

The formula is { 2^(((n-1)/2)+2) -2 } + 2^(n/2) if n is even.

You have to calculate power of 2 using Modular Exponentiation. You can read it about here https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/

This is my code https://www.codechef.com/viewsolution/26865644 Hope it helps :) Please upvote it if it helps.