Problem in GCDSET May cookoff

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:

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 :

1 Like

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…

1 Like

Nope… {22} gcd is not 11

But that’s unfair. It feels like cheating. Although I applied the most suitable logic, still getting WA.:cry:

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

1 Like

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 did in Python, still getting WA.
My solution

I’m also getting WA. Here is my Java solution.
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.

1 Like

Check this… I doubt that you are using big decimal…

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

3 4 3
6 7 3
2 10 3
3 10 3
2 9 3
3 9 3

Answers are
Ping me if you need more test cases

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

1 Like

That is why you do competitive bro… That is what you need to learn…