I think I have applied the correct concept in GCDSET yet I was getting Wrong Answer.Can anyone help me find the mistake. Here is the link of my submission:

https://www.codechef.com/viewsolution/24323299

Same problem with my code. I donâ€™t know why I am getting WA. I think I applied the appropriate approach. Can someone help me?

My Solution

I was having same problem. I think its some precision error.

I changed my code and its accepted now.

First change l and r to nearest divisible by g in range.

Then apply same logic.

Ceil and floor probably giving precision error for larger integers. Not sure though.

This is link to my solution : https://www.codechef.com/viewsolution/24317903

Shouldnâ€™t the solution for L: 14, R: 26 and G: 11 be 1? {22}?

I prefer not using inbuilt ceil and floor for this questionâ€¦ It may create issueâ€¦

Nopeâ€¦ {22} gcd is not 11

But thatâ€™s unfair. It feels like cheating. Although I applied the most suitable logic, still getting WA.

Thanks you are saying correct my submission also got accepted.

Problem is precision issueâ€¦ Try printing floor( (10^18-1)/10^18) you will get 1 instead of 0

Nothing is unfairâ€¦ Donâ€™t use inbuilt ceil and floor while handling very large valuesâ€¦

If you have then in p/q for use your own ceil and floorâ€¦ (double)p/q may create precision issueâ€¦ Check floor((double )(10^18-1)/10^18))

And why it is not unfair? The logic was correct, Implementation was correct, getting WA due to some precision issue???

Implementation was incorrectâ€¦you canâ€™t store it in doubleâ€¦ Use big double library then itâ€™s fineâ€¦

Iâ€™m also getting WA. Here is my Java solution.

https://ideone.com/6zueXo

Can anyone give me a counter-example that breaks my solution? Thanks!

Try for l=6,r=10 and g=4. Correct answer is 0, but your code give output 1.

i am so unhappy right now because i did not know that python ceil() would give me wrong answerâ€¦

6

3 4 3

6 7 3

2 10 3

3 10 3

2 9 3

3 9 3

Answers are

1

0

3

3

3

3

Ping me if you need more test cases

You are right, here is the mistake of mine. Thanks!

That is why you do competitive broâ€¦ That is what you need to learnâ€¦