ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1131. Copying

Someone please explain ceil() or log() function...
Posted by Urrong 1 Sep 2011 04:07
when i was writing my first solution i used ceil and log functions for calculating how many computers get copies with available cables (without using the same number of cables as one copy before)... so i calculated "int init = (int)ceil(log((double)k) / log(2.0));" and used that in my program but i got WA#6... then i wrote my own function that does exactly the same:
int getPow(int x)
{
    int c = 0;
    int n = 1;
    while(n < x){
        c++;
        n *= 2;
    }
    return c;
}

and then i got AC... can someone explain in what case the ceil and log functions would give wrong results.

THANK YOU
Re: Someone please explain ceil() or log() function...
Posted by Paul Vasiliev [SPbSU] 19 Jan 2012 02:14
I also didn't got that, but this is fact: I changed my ceils and logs to self-written function and got AC. It is still challenge for me to explain, why
Re: Someone please explain ceil() or log() function...
Posted by [SESC USU] Rudnev Vladimir 10 May 2012 13:01
I've do the same....
Maybe the problem is due to the compiler...
Re: Someone please explain ceil() or log() function...
Posted by Bogatyr 9 Oct 2012 11:17
Same here....and I compared my log2(x)) to (int)(log((double)x) / log(2.0)) for all x from 1 to 0x7FFFFFFF on my system and they're all identical.
Re: Someone please explain ceil() or log() function...
Posted by Accept 24 Feb 2013 08:29
You needn't use function log() or something else,You can use a const array like (2,4,8,16,32,64,128,256,512,1024....).