need help in problem odd in easy section

,

i write this code for odd problem in easy section i think my code is right as it is showing correct output for test cases according to the problem but on submitting it is showing time limit exceeded please help me in submitting the code in time and how can i optimize my code
here is my 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;

}

//