hey guys ,
i am trying to solve the following problem:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36
i have first populated an array for all possible numbers from 1 to
1000000 and then simply check for largest within [i,j]. But judge is
giving the verdict "wrong answer".
here is the code :
unsigned int a[1000000];
unsigned int count;
int main()
{
char str[30]={0};
unsigned int i,l,j,k,max;
unsigned int m;
unsigned int t;
for(l=1;l<1000000;l++)
{
m=l;
count=0;
for(;;)
{
count++;
if( m == 1)
{
a[l]=count;
break;
}
if(m%2)
m=3*m+1;
else
m=m/2;
}
}
while(fgets(str,30,stdin) !=NULL)
{
sscanf(str,"%u %u",&i,&j);
max=a[i];
if(i>j)
{
t=i;
i=j;
j=t;
}
for(k=i;k<=j;k++)
if(max < a[k])
max=a[k];
printf("%u %u %u\n",i,j,max);
}
return 0;
}
could someone please help me find the bug?
--
You received this message because you are subscribed to the Google Groups
"google-codejam" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-code?hl=en.