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

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
7 votes
Tags:
MathematicsOpenApprovedEasyMathamatics
Points:20
Tags:
Basic Math
Points:20
Tags:
Binary SearchMath BasicMath