#include<iostream>
using namespace std;
int cbin(long long v[],long long n,long long x)//BINARY SEARCH
{
long long i=0,j=n-1,m;
while(i<=j)
{
m=(i+j)/2;
if(v[m]==x)
return 1;
else if(v[m]<x)
i=m+1;
else j=m-1;
}
return 0;
}
void insert(long long v[],long long &n,long long x)//INSERTION SORT
{
long long i;
for(i=n;i>0&&v[i-1]>x;i--)
v[i]=v[i-1];
v[i]=x;
n++;
}
int main()
{
long long x,v[10000],n=1;
cin>>x;
v[0]=x;
while(x>1)
{
if(x%2==0)
x/=2;
else
x=3*x+3;
if(cbin(v,n,x))
{
cout<<"NIE";
break;
}
else
{
insert(v,n,x);
}
}
if(x<=1)
cout<<"TAK";
return 0;
}
Gives me wa ..simple algorithm ...i store every number in an array and if it gest repeated it means infinite loop...if gets under or equal to 1 not
created
last reply
- 12
replies
- 393
views
- 3
users
- 1
link