https://www.codechef.com/CSK2021/problems/SACHDUB

PROBLEM LINK:

https://www.codechef.com/CSK2021/problems/SACHDUB

Author: Abhishek Yadav
Tester: Abhishek Yadav
Editorialist: Abhishek Yadav

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Array,maths

PROBLEM:

You are given an array of size N and you have to perform following operations on it.

  1. You have to select 1st and last element form array and find it’s positive difference. Then again find the positive difference between 2nd and second last element. then 3rd and third last element and so on.

  2. Add this all differences. If the sum of all the positive differences is a prime number then you have to print “KIT” else you have to print “KAT”.

(Note 1: The array size will always a even number).

(Note 2: If the sum of differences is equal to zero OR one then print “KITKAT”).

QUICK EXPLANATION:

Just find the absolute difference of the first element of array and last element of the array then find the absolute difference of 2nd element and 2nd last element and so on. calculate the summission of all this absolute differences

EXPLANATION:

Just find the absolute difference of the first element of array and last element of the array then find the absolute difference of 2nd element and 2nd last element and so on. calculate the summission of all this absolute differences. if the summission of the absolute differences is a prime number the you have to print “KIT” else if the summission is not a prime number just print “KAT”.
If the summission is equla to zero or one then you have to print “KITKAT”.
because 0 and 1 are nither prime nor composite.

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
//typedef long long ll;
//typedef vector vi;
//typedef pair<int,int> pi;
//#define F first
//#define S second
//#define PB push_back
//#define MP make_pair
#define noob(i,a,b) for (int i = a; i < b; i++)
//REB(i,(starting point e.g 0,1,etc),(endpoint e.g n))
//sort(a,a+n,greater());
//#define SQ(z) (z)*(z)
//#define SUM(n) (n(n+1))/2
using namespace std;
void testcase()
{
int n,sum=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int j=n-1;
for(int i=0;i<n;i++)
{
if(i<n/2)
{
sum+=abs(a[i]-a[j]);
j–;
}
else
{
break;
}
}
//cout<<sum<<" “;
if(sum==1 || sum==0)
{
cout<<“KITKAT”<<”\n";
}
else
{
int flag=0;
for (int i = 2; i <= sum/2; ++i)
{
if (sum % i == 0)
{
flag = 1;
break;
}
}
if(flag==0)
{
cout<<“KIT”<<"\n";
}
else
{
cout<<“KAT”<<"\n";
}
}

}
//
//
//
int main()
{

int t;
cin>>t;
while(t–)
{
testcase();
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
//typedef long long ll;
//typedef vector vi;
//typedef pair<int,int> pi;
//#define F first
//#define S second
//#define PB push_back
//#define MP make_pair
#define noob(i,a,b) for (int i = a; i < b; i++)
//REB(i,(starting point e.g 0,1,etc),(endpoint e.g n))
//sort(a,a+n,greater());
//#define SQ(z) (z)*(z)
//#define SUM(n) (n(n+1))/2
using namespace std;
void testcase()
{
int n,sum=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int j=n-1;
for(int i=0;i<n;i++)
{
if(i<n/2)
{
sum+=abs(a[i]-a[j]);
j–;
}
else
{
break;
}
}
//cout<<sum<<" “;
if(sum==1 || sum==0)
{
cout<<“KITKAT”<<”\n";
}
else
{
int flag=0;
for (int i = 2; i <= sum/2; ++i)
{
if (sum % i == 0)
{
flag = 1;
break;
}
}
if(flag==0)
{
cout<<“KIT”<<"\n";
}
else
{
cout<<“KAT”<<"\n";
}
}

}
//
//
//
int main()
{

int t;
cin>>t;
while(t–)
{
testcase();
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
//typedef long long ll;
//typedef vector vi;
//typedef pair<int,int> pi;
//#define F first
//#define S second
//#define PB push_back
//#define MP make_pair
#define noob(i,a,b) for (int i = a; i < b; i++)
//REB(i,(starting point e.g 0,1,etc),(endpoint e.g n))
//sort(a,a+n,greater());
//#define SQ(z) (z)*(z)
//#define SUM(n) (n(n+1))/2
using namespace std;
void testcase()
{
int n,sum=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int j=n-1;
for(int i=0;i<n;i++)
{
if(i<n/2)
{
sum+=abs(a[i]-a[j]);
j–;
}
else
{
break;
}
}
//cout<<sum<<" “;
if(sum==1 || sum==0)
{
cout<<“KITKAT”<<”\n";
}
else
{
int flag=0;
for (int i = 2; i <= sum/2; ++i)
{
if (sum % i == 0)
{
flag = 1;
break;
}
}
if(flag==0)
{
cout<<“KIT”<<"\n";
}
else
{
cout<<“KAT”<<"\n";
}
}

}
//
//
//
int main()
{

int t;
cin>>t;
while(t–)
{
testcase();
}
return 0;
}