#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 10005
typedef long long ll;
int main()
{
ll a, b, res, ans, counter, cas = 0;
int t_case;
cin >> t_case;
while(t_case--)
{
cin>> a>> b;
counter = 0;
if(((b - a) + 1) == 1)
{
res = a % 3;
if(res == 0 || res == 2)
counter = 1;
}
else if((a % 3 == 0 && b % 3 == 0) || (a % 3 == 2 && b % 3 == 2) || (a % 3 == 2 && b % 3 == 0))
{
res = b - a;
ans = res / 3;
counter = res - ans + 1;
}
else
{
res = b - a;
ans = res / 3;
counter = res - ans;
}
cout<< "Case "<< ++cas<< ": "<< counter << endl;
}
return 0;
}
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define pf printf
#define sf scanf
#define loop(i, n) for(i=0; i<(n); i++)
#define MAX 10005
typedef long long ll;
int main()
{
ll a, b, res, ans, counter, cas = 0;
int t_case;
cin >> t_case;
while(t_case--)
{
cin>> a>> b;
counter = 0;
if(((b - a) + 1) == 1)
{
res = a % 3;
if(res == 0 || res == 2)
counter = 1;
}
else if((a % 3 == 0 && b % 3 == 0) || (a % 3 == 2 && b % 3 == 2) || (a % 3 == 2 && b % 3 == 0))
{
res = b - a;
ans = res / 3;
counter = res - ans + 1;
}
else
{
res = b - a;
ans = res / 3;
counter = res - ans;
}
cout<< "Case "<< ++cas<< ": "<< counter << endl;
}
return 0;
}
Can you please explain the procedure? your approach is unclear ! Thanks in advance
ReplyDelete