This Forum is in read only mode now.

You are not logged in. Please login at www.codechef.com to post your questions!

×

Why both code having same logic don't work? [SUBPRNJL]

 0 I got WA when used m = ceil((float(k)/float(r-l+1)); but got AC when used m = k/(r-l+1) + k%(r-l+1)==0?0:1; Can somebody tell me the difference between the two? My submission using both: https://www.codechef.com/viewsolution/23444985 - using ceiling function https://www.codechef.com/viewsolution/23444732 - using ternary operator asked 18 Mar, 22:23 4★karasu 23●1●5 accept rate: 0%

 2 float type is single-precision floating point and it has significand precision of 24 bits. This means that it cannot accurately represent integers above $2^{24}$, which is much lower than the maximum value of $k$ which is $10^9$. This introduces an error in your ceil calculation. An easy way to compute ceil(a / b) for integers a, b without involving floats is (a + b - 1) / b. answered 24 Mar, 05:16 6★meooow ♦ 7.3k●7●20 accept rate: 48% Thank you tried with with long double and it worked and also thanks for the tip for calculating ceil function. Much appreciated. (25 Mar, 11:08) karasu4★ Loved the (a+b-1)/b tip! (25 Mar, 12:25)
 0 Let k=8, (r-l+1)=3 Then the first value of m is 4. While the second line checks whether 8/3 + 8%3 == 0, which simplifies to 4==0. I haven't seen the rest of your code, but this observation might help you. answered 21 Mar, 12:02 3★udayan14 86●4 accept rate: 0% the value of m in 1st is 3, ceil(8/3)=ceil(2.6)=3 You calculated wrong. (24 Mar, 03:52) karasu4★

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×348
×19
×8

question asked: 18 Mar, 22:23

question was seen: 3,329 times

last updated: 25 Mar, 12:45