AYou need to speed up your NZD ( GCD ) function, try searching for Euklid's recursive algorithm on google.
DThanks for the posts but its still not working. Yes I use the Euclid algorithm.
bwell, you are using
nzd( a, b ) = nzd( a-b, b )
but you can use
nzd( a, b ) = nzd( a % b, b )
DWait wait, can you exactly point in my original post, where is the error?
Hvala vam puno.
myou have the Euklid algorithm on wikipedia and there is a code
Dboris4 can you please explain the code? Now it doesn't work at all.
Thanks in advance.
byes, i can :)
to find NZD ( GCD ) for 2 numbers in O( log( max( a, b ) ) ) time you use Euclid's algorithm.
it goes like this
a,b --> read those 2 or something like that
int r = a % b;
while ( r > 0 )
{
a = b;
b = r;
r = a % b;
}
and the result is b.
this one up you get, do with recursion ( it is easier to type and smaller :) )
and it goes
int nzd( int a, int b )
{
if ( b == 0 )
return a;
return nzd( a % b, b );
}
DThanks for the code. Why still I Got these Wrong Results for all of the test.
http://www.z-trening.com/new/www/html/submit.php?submit=5000000153
bhmmm... i'm not sure but try:
put << endl at the end of your output
int function you have ( long a, long b ), put
( long long a, long long b )
Dlol. this is very strange. I tried with 3 algorithms and still could not start working it. I am trying it, and it works, but it doesn't pass the tests. I probably need to contact admin.
bchange:
long long nzd( long a, long b )
to:
long long nzd( long long a, long long b )
DNow it works. Thank you very much for the help Boris. How many years of experience do u have with programming ?
bhmmm... i think less then 2 years.
I think i started programming in August 2007