 # Misha and Nice Sets (Problem C of May Cook Off)

I worked out a solution which is not passing all the test cases. I matched it with solved solutions and I can’t tell the difference. Please debug it.

Code:

``````#include<iostream>
#include<stdio.h>

#define ll long long int

using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
ll l,r,g;
cin>>l>>r>>g;

ll a,b;

if(g<l) a=(l/g)+1;
else a=1;

b=r/g;
ll z=b-a+1;
if(z==1 && b>1) z=0;

printf("%lld\n",z);
}
return 0;
}``````

i think one of the test case for which your solution is giving wrong answer is
l=4 r=5 and g=1

I have tried AP approach but getting WA.i have checked it with various test cases still can’t figure out problem.
#include
#define l1 long long int
using namespace std;
int main() {
int t;
cin>>t;
while(t)
{
t–;
l1 l,r,g;
cin>>l>>r>>g;
if(r<g)
cout<<0<<endl;
else
{
l1 mod1=r%g;
l1 ap_last_term1=r-mod1;
l1 ans1=(ap_last_term1-g)/g + 1;
l1 mod2=(l-1)%g;
l1 ap_last_term2=l-1-mod2;
l1 ans2=(ap_last_term2-g)/g + 1;
cout<<ans1-ans2<<endl;
}
}
return 0;
}

Thanks…actually it was failing when l%g==0, s I replaced (l/g) in line 20 with (ceil((long double)l/g) and it passed…
Thanks again

Please tell error in my code.

{
ull l,r,g;
cin>>l>>r>>g;
ull start=0,x,end=0;
bool flag=true;
if(l<g and g<=r)
l=g;
if(g>r)
cout<<“0”<<e;
else
{
x=l;
while(1)
{
if(x>r)
{
flag=false;
break;
}
if(x%g==0)
{
start=x;
break;}
x++;
}
if(!flag)
cout<<“0”<<e;
else{
x=r;
while(1)
{
if(x<l)
{
flag=false;
break;
}
if(x%g==0)
{
end=x;
break;
}
x–;
}
if(!flag)
cout<<“0”<<e;
else
cout<<((end-start)/g)+1<<e;
}

``````	}
}``````

Can you post your code again but with some proper indentation, like my code on the top!
It would be easy for me to debug it.
Thanks

It is not getting indenting please copy paste on visual studio and format document.
Thanks for help.

How do you guys even think like this /author - Ashutosh Chitranshi/
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << “\n”
#define pow2(x) ((x)*(x))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ll long long int
#define eb emplace_back
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define ff first
#define ss second
#define nl “\n”
typedef vector vi;
typedef vector vl;
typedef vector< vi > vvi;
typedef vector< vl > vvl;
typedef pair< int,int > ii;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;
typedef map< int,int> mii;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
ll l,r,g;
cin >> t;
while(t–)
{
cin >> l >> r >> g;
if(g>r)
{
cout << “0” << nl;
continue;
}
if(g==r)
{
cout << “1” << nl;
continue;
}
else
{
ll temp1 = r/g;
ll temp2 = l/g;
if(l%g==0)
temp2–;
cout << temp1-temp2 << nl;
}
}
return 0;
}

Help finding error in mine