SOD3 - Editorial

1
2 4
1 Like

Thanks :raised_hands:

1 Like

1
2 4
correct answer-1

1 Like
1
3 4

Thanks :raised_hands:

How are you guys getting to know what test case is failing? How can I see the test cases?

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

I understood the soln but what is wrong with my approach… Can someone tell me?

Help me …
Submission Link : CodeChef: Practical coding for everyone
Plz tell any testcase where this is failing, Only one task fails to pass .

Please, people, read the thread and try the testcases that other people have posted!

1                       
3 1000000000000000000
    l = ceil((1.0 * l) / 3) * 3;
    r = floor((1.0 * r) / 3) * 3;
    ans = (r - l) / 3 + 1;

Why is this wrong?

Please post your full, formatted code :slight_smile:

1 Like

here

That solution is AC.

Sorry my bad. here

1 Like
1
1 999999999999999679
1 Like

Thanks! Can you explain why r = floor((1.0 * r) / 3) * 3; this is giving wrong result?

Floating point arithmetic is inaccurate.

1 Like

Thank You
@anshu23_1999 it helped. I modified my code. Now its passing all test cases.

Found this simple

//This code is given by- kiran_abc02
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define endl ‘\n’
#define vec vector
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll c;
cin>>c;
while(c–){
ll a,b;
cin>>a>>b;
ll n=(b-a)/3;
if(a%3==2 && b%3==1){
cout<<n+1<<endl;
}
else if(a%3==0 || b%3==0){
cout<<n+1<<endl;
}
else{
cout<<n<<endl;
}
}

return 0;

}