Hello
I found a contrast .....
Please have a look here

#include <stdio.h>

unsigned long findMaxCycleLength(unsigned long min, unsigned long max);
unsigned long findCycleLength(unsigned long n);

int main(int argc, char** argv)
{
    unsigned long min, max, num = 0;

    while(scanf("%li %li", &min, &max) != EOF)
    {
        printf("%li %li ", min, max);
        if(min > max)
        {
            min^=max;
            max^=min;
            min^=max;
        }
        num = findMaxCycleLength(min, max);
        printf("%li\n", num);
    }
}

unsigned long findMaxCycleLength(unsigned long min, unsigned long max)
{
    unsigned long temp, i;
*    unsigned long n = findCycleLength(max);
//  unsigned long n = 0 ;*
    for(i = min; i < max; i++)
    {
        temp = findCycleLength(i);
        if(temp > n)
        {
            n = temp;
        }
    }

    return n;
}

unsigned long findCycleLength(unsigned long n)
{
    if(n == 0) return 0;
    unsigned long count = 1;
    while(n != 1)
    {
        if(n%2 == 1)
        {
            n = 3*n+1;
        }
        else
        {
            n = n/2;
        }
        count++;
    }
    return count;
}

here,
When I compile it with*    unsigned long n = findCycleLength(max); * it
seems ok.
But when I use *//  unsigned long n = 0 ; *it gives me wrong answer.
Could you please tell me why it gives me WA if I taste it from 0 ?* int n =
0 ; is also the  same problem
*


[Non-text portions of this message have been removed]

Reply via email to