THINKBIT - Strange Pattern (Medium)

Mr. X has learned bitwise operators. With this ability, he once again wants to make a fibonacci function. Same as before, for x=1 and x=2 the function prints out 2 and 3 respectively. But the problem still occurs, every number after 2 also prints out 3.

Again, Mr. X given up on fixing the function and instead challenges you to recreate the function that he created. Since he wants to study more bitwise operators, he only wants you to do a single statement using only bitwise operators. You can also use numbers and the letter 'x'.

Mr. X has given you his code for you to edit, but you can only edit a certain part of the code.

#include <stdio.h>

int count(int x){

return edit this part;


int main(){for(int i=1;i^10001;i++)printf("%d %d\n",i,count(i));return 0;}

#include <stdio.h>
int count(int x){
return (x+1)%x+2
int main(){
for( int i=1 ; i-1001 ; i++ ) printf("%d %d\n",i,count(i));
return 0;

Mr. X will first check the correctness of the output. If the output is correct, he then will check the code. If there is anything that violates the rule above, the result will be "compilation error". Changing the code other than the allowed part may also result in a compile error.



No input.


1 2
2 3
3 3
4 3
... and so on ...
9998 3
9999 3
10000 3 

Click here to see all problems in this series!

hide comments
darryl: 2016-08-19 08:26:32

whew, finally got it.
don't confuse bitwise operators vs logical operators.

meettaraviya: 2016-01-05 20:57:04

why is it incorrect?

Daniel Carvalho: 2015-02-23 03:26:52

Answering myself: yes.

Daniel Carvalho: 2015-02-22 15:33:27

Is the result longer than 20 characters?

Bhavik: 2013-12-28 19:37:52

1->2 is creating problems!!!still thinking....:(

Orni: 2013-09-14 16:20:29

Can we use bit shifts ?

THE_SCORPION: 2013-09-13 20:00:50

any hint ?

Andy: 2013-06-02 18:22:54


No. Only bitwise, numbers, and x are allowed.

Last edit: 2013-06-02 18:23:43
Surya kiran: 2013-06-02 09:47:16

can we use '(' and ')' ??

Added by:Andy
Time limit:1s
Source limit:250B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C++ 4.3.2
Resource:own problem