The problem is “Yet another number game” problem from Easy portion of practice portal.Its code is NUMGAME.
From the past one day I have been trying but have been constantly getting TLE. Please people help me.
Below is my code.
#include< stdio.h >
void perform(int n)
{
int flag=1;
int i=n/2;
while(i>=1)
{
if(n%i==0)
{
if(flag==1)
flag=0;
else
flag=1;
n-=i;
i=(n/2)+1;
}
i--;
}
if(flag==1)
printf("\nBOB\n");
else
printf("\nALICE\n");
}
int main(void)
{
int t,count=0,i;
scanf("%d",&t);
unsigned long n;
while(count < t)
{
scanf("%d",&n);
perform(n);
count++;
}
return 0;
}