PROBLEM LINK:
Author: Abhishek Yadav
Tester: Abhishek Yadav
Editorialist: Abhishek Yadav
DIFFICULTY:
EASY
PREREQUISITES:
Math etc.
PROBLEM:
Since The Price of Bitcoins is rising day by day. The team of four buisness-man (Yash,Tejas,Niranjan,sujal)(Yash,Tejas,Niranjan,sujal) who have purchased some bitcoins in 2009 decided to sell them. Because they think it’s the right time to sell their bitcoins.
The problem here is that they have forget the password for their bitcoin account. But they know the algorithm to find the password.
The algorithm is as follow
i) Each business man will chose two numbers but the condition here is that the 2nd number should always be less or equal to 1st number.
ii) Now they have to subtract their 2nd number from 1st till they get the smallest possible non- negative number. (egeg : - suppose the 1st number is 7 and 2nd number is 2 then we will subtract 2nd number i.e 2 for 3 three times and we will left with 1 which is smallest non-negative number).
iii) Now after each business man find’s their smallest non-negative number. All of them will add their smallest non-negative number.
iv) Now if their addition is a composite number then they successfully got the access else not.
So you have to help them to get the access to their account. If they get happy with your work so maybe they will give you some of their bitcoins. but the reward is secondary our first goal is to help them to get access their account.
So You are given 2 array of size N=4. 1st array will contain the 1st number of all business man. 2nd array will contain the 2nd number of all business man.
you have to subtract the iith value of 1st array with iith value of 2nd array. till you get the smallest non-negative number.
Apply the same thing on whole array.
Now ADD all the smallet non-negative numbers and check if it is composite number or not. If the number is composite Print “Access Granted” else print “Access Denied”.
(NOTE : If the value of addition is zero or one print “Access Denied”).
(NOTE : All the answers are case sensitive).
QUICK EXPLANATION:
EXPLANATION:
In this question you are given two arrays of same size and you have to select the every a[i] element and you have to find the modulo of the a[i] with b[i] element and add the every ith element to the sum and lastly you have to check weather the sum of all this modulo is composite number or not if the Number is Composite number. Then you have to print “Access Granted” else you have to print “Access Denied”.
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 composite(int sum)
{
ll cnt;
for(ll i=1;i<=sum;i++)
{
if(sum%i==0)
cnt++;
}
if(cnt==2)
cout<<“Access Denied”<<“\n”;
else
cout<<“Access Granted”<<“\n”;
}
int main()
{
ll t;
cin>>t;
while(t–)
{
ll th=0,yh=0,nh=0,sh=0,tl=0,yl=0,nl=0,sl=0;
cin>>th>>yh>>nh>>sh;
cin>>tl>>yl>>nl>>sl;
ll ft=0,fy=0,fn=0,fs=0;
ft=th%tl;
//cout<<ft<<" “;
fy=yh%yl;
//cout<<fy<<” “;
fn=nh%nl;
//cout<<fn<<” “;
fs=sh%sl;
//cout<<fs<<” “;
ll sum=ft+fy+fn+fs;
//cout<<sum<<” “;
if(sum==1 || sum==0)
{
cout<<“Access Denied”<<”\n";
}
else
{
composite(sum);
}
}
}
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 composite(int sum)
{
ll cnt;
for(ll i=1;i<=sum;i++)
{
if(sum%i==0)
cnt++;
}
if(cnt==2)
cout<<“Access Denied”<<“\n”;
else
cout<<“Access Granted”<<“\n”;
}
int main()
{
ll t;
cin>>t;
while(t–)
{
ll th=0,yh=0,nh=0,sh=0,tl=0,yl=0,nl=0,sl=0;
cin>>th>>yh>>nh>>sh;
cin>>tl>>yl>>nl>>sl;
ll ft=0,fy=0,fn=0,fs=0;
ft=th%tl;
//cout<<ft<<" “;
fy=yh%yl;
//cout<<fy<<” “;
fn=nh%nl;
//cout<<fn<<” “;
fs=sh%sl;
//cout<<fs<<” “;
ll sum=ft+fy+fn+fs;
//cout<<sum<<” “;
if(sum==1 || sum==0)
{
cout<<“Access Denied”<<”\n";
}
else
{
composite(sum);
}
}
}
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 composite(int sum)
{
ll cnt;
for(ll i=1;i<=sum;i++)
{
if(sum%i==0)
cnt++;
}
if(cnt==2)
cout<<“Access Denied”<<“\n”;
else
cout<<“Access Granted”<<“\n”;
}
int main()
{
ll t;
cin>>t;
while(t–)
{
ll th=0,yh=0,nh=0,sh=0,tl=0,yl=0,nl=0,sl=0;
cin>>th>>yh>>nh>>sh;
cin>>tl>>yl>>nl>>sl;
ll ft=0,fy=0,fn=0,fs=0;
ft=th%tl;
//cout<<ft<<" “;
fy=yh%yl;
//cout<<fy<<” “;
fn=nh%nl;
//cout<<fn<<” “;
fs=sh%sl;
//cout<<fs<<” “;
ll sum=ft+fy+fn+fs;
//cout<<sum<<” “;
if(sum==1 || sum==0)
{
cout<<“Access Denied”<<”\n";
}
else
{
composite(sum);
}
}
}