Equal Beauty CodeChef SnackDown 2021 Round 1A Question The beauty of an (non-empty) array of integers is defined as the difference between its largest and smallest element. For example, the beauty of the array [2,3,4,4,6] is 6−2=4. An array A is said to be good if it is possible to partition the elements of A into two non-empty arrays B1 and B2 such that B1 and B2 have the same beauty. Each element of array A should be in exactly one array: either in B1 or in B2. For example, the array [6,2,4,4,4] is good because its elements can be partitioned into two arrays B1=[6,4,4] and B2=[2,4], where both B1 and B2 have the same beauty (6−4=4−2=2). You are given an array A of length N. In one move you can: Select an index i (1≤i≤N) and either increase Ai by 1 or decrease Ai by 1. Find the minimum number of moves required to make the array A good. Input Format The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow. Each test
Chef and Semi-Primes CodeChef SnackDown 2021 Beginner Practice Contest
Question:
Chef likes prime numbers. However, there is one thing he loves even more. Of course, it's semi-primes! A semi-prime number is an integer which can be expressed as a product of two distinct primes. For example, is a semi-prime number, but , and are not.
Chef is wondering how to check if an integer can be expressed as a sum of two (not necessarily distinct) semi-primes. Help Chef with this tough task!
Input:
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains a single integer .
Output:
For each test case, print a single line containing the string
"YES"
if it is possible to express as a sum of two semi-primes or "NO"
otherwise.Constraints:
1≤T≤200
1≤N≤200
Example Input:
3
30
45
62
Example Output:
YES
YES
NO
Explanation:
Example case 1: can be expressed as .
Example case 2: can be expressed as .
Example case 3: cannot be expressed as a sum of two semi-primes.
Program Code in C++
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
bool check_prime(ll a)
{
for(ll i=2;i*i<=a;i++){
if(a%i==0)
return false;
}
return true;
}
ll p[2001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for(ll i=2;i<=200;i++){
for(ll j=i+1;i*j<=200;j++){
if(check_prime(i)&&check_prime(j))
p[i*j]=1;
}
}
ll t,n;
cin>>t;
while(t--){
cin>>n;
bool fl=false;
for(ll i=2;i<n;i++){
if(p[i]&&p[n-i]){
fl=true;
break;}
}
if(fl)
cout<<"YES\n";
else
cout<<"NO\n";
}
return 0;
}
Important Links
More Information
CodeChef is one of the largest online coding platform and SnackDown is one of it's of grandest programs held ever year. SnackDown is a global programming event that invites programmers all over the world to participate in India's most prestigious multi-round programming competition. SnackDown is open to everyone who has a knack in programming.
This question that is Chef and Semi-Primes is of CodeChef SnackDown 2021 Beginner Practice Contest. Here you will get a brief explanation of the problem and after reading the explanation if you are still stuck and have no clue to understand the problem then you can visit the solution of the question given above.
Hope you learnt something from this explanation and solution. Code it guys, practice coding more and more.
Comments
Post a Comment