A shop has N number of products. The owner of the shop wishes to create two separate compartments in his stock room for all the products. He wants items to be grouped in such a way that all the products whose ID is a prime number stay in the first compartment, and all products whose ID is a non-prime number stay in the second compartment. Write an algorithm to help the shop owner with his product storage, so that all products with an ID that is a prime number can be stod together, followed by the products with an ID that is a non-prime number. Input The first line of the input consists of an integer - numProducts representing the number of products in shop (N). The second lines consist of N space-separated integers-prodID₁, prodID2,.... prodIDN representing the IDs for the products in the shop. Output Print N space-separated integers representing all prime number IDs followed by all non-prime number IDs in the order in which they appear in the input. Constraints 0 < numProducts ≤ 10³ 2 ≤ prodID ₁, prodID ₂2. prodiDN≤ 103 Example Input: 7 2953 14 80 17 Output: 25317914 80 Explanation: In the given input the prime numbers are - [2, 5, 3, 17] and the non-prime numbers are - [9. 14,80] So, the output is [2, 5, 3, 17, 9, 14, 80].
Answers
Answer:
jjhhg the chapter is a great day and Usha Khanna of a lot of time and Usha Mangeshkar the chapter of alpha and Omega phi Omega phi beta sorority sisters of mercy and grace of God bless your heart and soul the chapter of my class link for good morning I will be on dated 29 of alpha phi alpha fraternity brothers are not the intended recipients
Input:
6
87 103 229 41 8 86
3 1 9 2 1 2
7 -21 30 0 -4 -3
Output
261 2061
Explanation:
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int noOfProducts=sc.nextInt();
int price[]=new int[noOfProducts];
int distance[]=new int[noOfProducts];
int sku[]=new int[noOfProducts];
for(int i=0;i<noOfProducts;i++)
price[i]=sc.nextInt();
for(int i=0;i<noOfProducts;i++)
distance[i]=sc.nextInt();
for(int i=0;i<noOfProducts;i++)
sku[i]=sc.nextInt();
int finalPrice[]=new int[noOfProducts];
int count =0;
for(int i=0;i<noOfProducts;i++)
{
if(sku[i]>0)
{
finalPrice[count]= price[i] * distance[i];
count++;
}
}
for(int i=0;i<count;i++)
{
System.out.print(finalPrice[i]+" ");
}
}
}