ceil((double)x/n); x <= 10^12 and n <10^6; can anyone provide a test case or something I got hacked many times but was unable to find a mistake
| № | Пользователь | Рейтинг |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | jiangly | 3631 |
| 4 | Kevin114514 | 3574 |
| 5 | maroonrk | 3521 |
| 6 | strapple | 3515 |
| 7 | Radewoosh | 3461 |
| 8 | tourist | 3428 |
| 9 | turmax | 3378 |
| 10 | Um_nik | 3376 |
| Страны | Города | Организации | Всё → |
| № | Пользователь | Вклад |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 140 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
ceil((double)x/n); x <= 10^12 and n <10^6; can anyone provide a test case or something I got hacked many times but was unable to find a mistake
| Название |
|---|



I can give you a reason why it can be wrong: because of how doubles are stored (IEEE 754), they might not be accurate, and that can lead to inaccurate result
if you want ceil, then use
(x + n - 1) / nis there any test case to show this i am unable to find one
it fails for bigger number like if you try to do 100000000000000001/100000000000000000 it will give you 1 directly but ceil of this should be 2
but test case allow 10^12 for x and 10^6 for n
You can try stress-testing. I believe
ceil()will cause precision error by nature, regardless of the constraints.but if we give by this method ie (x+n-1)/n then wont it lead to overflows due to addition?
yes
then how does N8LnR2Nqf8Q4FN says to give (x+n-1)/n and not
ceil(double(x)/n)
I don't think any problem setter would be that evil.
Also, if you are afraid of overflow, you can try
x / n + (x % n != 0), although it requires more divisions, which is slower and uglier (but I guess it's easier to understand).And,
__int128is also an option as well, you can have a look at it.