Yet Another Number Game

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

#include
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t,n,x;
cin>>t;
while(t–)
{
cin>>n;
if(n%2==0)
cout<<“ALICE\n”;
else
cout<<“BOB\n”;
}
return 0;
}