Trick with the cards
Practice
3.8 (836 votes)
Ad Hoc
Simulation
Easy
Mathematics
Open
Approved
Mathamatics
Problem
24% Success 13275 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Mr. X is performing a trick with the cards. He has N cards, lets name them 1.....N, on a round table. So card 1 is in between 2nd card and Nth card. Initially all cards are upside down. His trick involves making all cards face up.

His trick is whenever he taps on a card, it flips (if card was originally upside down, after flipping its faces up, and vice-versa), but he is no ordinary magician, he makes the two adjacent cards (if any) also to flip with the single tap. Formally, if he taps ith card, then i-1, i, i+1 cards are flipped. (Note that if he taps Nth card, then he flips (N-1)th, Nth and 1st card.)

Our magician needs a helper, to assist him in his magic tricks. He is looking for someone who can predict minimum number of taps needed to turn all the cards facing up.

Input :
First line of input contains T, the number of test cases. Then T lines follows, each line contains N, the number of cards for that particular case.

Output :
Print the output for each case in a single line.

Constraints :
1 <= T <= 10^5
0 <= N <= 10^15

Sample Input
2
2
3
Sample Output
1
1
Code Editor

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Submissions
Please login to view your submissions
Similar Problems
Points:20
2 votes
Tags:
Basic ProgrammingBit manipulationBasics of Bit ManipulationEasymathsBit Manipulation
Points:20
2 votes
Tags:
MathObservationBasic MathC++
Points:20
1 votes
Tags:
MathematicsEasyMathematicsMathamatics
Editorial

Login to unlock the editorial