how can i optimize this code

please help me in optimizing this code

#include<stdio.h>

int main()

{

int n,i,y,t,safe=0;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<=n;i++)
{
    int x=i;
    y=i;
    while(x>1&&x%2==0)
    {
        x=x/2;
    }
    if(x==1)
    {
        if(y>safe)
        safe=y;
    }
}
printf("%d\n",safe);
}

return 0;

}

Hello nishant_25,

I wrote a tutorial on this problem which you can find here.

If any doubts remain, please feel free to ask!! We are here to help!

Best regards,
Bruno

PS: I deleted your other post, so we don’t keep duplicate posts here…

can you please explain me that how you said
“That way involves logarithms of base 2.”
and if there is any way in which i can optimize my code

//