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;
}M

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.

DO NOT USE ANY WHITESPACE ON THE EDITED PART

Input

No input.

Output

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!


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

hide comments
2016-08-19 08:26:32 darryl
whew, finally got it.
don't confuse bitwise operators vs logical operators.
2016-01-05 20:57:04
1<<1^!!(x>>1)
why is it incorrect?
2015-02-23 03:26:52 Daniel Carvalho
Answering myself: yes.
2015-02-22 15:33:27 Daniel Carvalho
Is the result longer than 20 characters?
2013-12-28 19:37:52 Bhavik
1->2 is creating problems!!!still thinking....:(
2013-09-14 16:20:29 Orni
Can we use bit shifts ?
2013-09-13 20:00:50 THE_SCORPION
any hint ?
2013-06-02 18:22:54 Andy
@surya

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

Last edit: 2013-06-02 18:23:43
2013-06-02 09:47:16 Surya kiran
can we use '(' and ')' ??
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.