Here I have N number of cards numbered from 1 to N placed in a round table such that card 1 is between card 2 and card N . All the cards are initially upside down. The aim is to turn all the cards face up.
Let's say we touch a card i, touching the card i will turn the cards i-1,i,i+1 face up. similarly touching the card N will turn the cards N-1,N,1st card face up. I want to determine the minimum number of touches required to face up all the cards.
here is what i have been trying in python
q = int(raw_input())
if q==1 or q==2:
print "1"
else:
r = q%3
l = q/3
print r+l
q can be as big as 10^20.
What's wrong with above logic and In case the above logic is completely wrong what should be the correct approach.
It should be something along the lines of:
So an easy way to neat way to code this'd be: