you CAN do this : for (int i=10;i<20;i++) ...
if you write in C++
and you CANNOT in ANSI C
It is simple really.
As for the count word. It is possible not to be reserved, but I had this problem with other word, but I am not sure witch exactly. I really don`t wrire on DJGPP, the only way to be sure about is or isn`t is to compile it under the judge`s version.
Tsvetan Bogdanov.
from Brain Explorer - Sofia University - FMI 2
e-mail: zbogi@yahoo.com
One cannot get 0.000 time on 100 as far as I know. But the system has a timing glitch and so it happens that some people, including me, have been mistimed. There are a couple of posts in the misc section.
But generally you need a very good algorithm and/or IO routines,
Ivor
There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).
I'm still getting an error. I modified my cycle algorithm to be recursive, too. I noticed that on a couple of numbers, ie 113383, if I try to caclulate the cycles, the number will be greater than 2^32. So, I'm not sure what to do.
[cpp]
/* @JUDGE_ID: 100 C++ */
/* @begin_of_source_code */
#include <iostream.h>
int cycle(int n);
int main()
{
int i, j, count, temp, m, n, max;
count = 0;
while(!(cin.eof()))
{
cin >> i >> j;
if (i > 0 && i < 1000000 && j > 0 && j < 1000000)
{
if (i > j)
{
n = i;
m = j;
}
else
{
m = i;
n = j;
}
max = -100;
for ( ; m <= n; m++)
{
temp = cycle(m);
if (temp > max)
max = temp;
}
cout << i << " " << j << " " << max << endl;
}
}
return 0;
}
int cycle(int n)
{
if (n == 1)
return 1;
else if (n % 2)
return cycle(3*n + 1) + 1 ;
else
return cycle(n/2) + 1;
}
the only mistake i can find is for n = 55. Your output is 113 and the correct output is 114. Since f(2n) = f(n)+1, it will affects the result of 110,220,440,etc as well. you should try to debug your program using those input and find your mistake.
good luck
the problem is not in cycle() (cycle(55)==113 is good). you repeat the last test case, use "while (cin >> i >> j)" instead. btw don't worry about integer overflow in cycle() the problem description states it won't happen.