InterviewSolution
| 1. |
Was score 2 40Kit selectionBob and Alice start painting. There are N numbers of painting kits. Thethkit has a strength of Az-10They need to select these kos Bob got the first chance to selea a kit and he selected a minimum number of kits such that he can make thepainting quickiy. Now, the remaining kits are selected by AliceBob can finish his painting before Atce. Fi and only r the total strength of his bits is grester than Alice'sFind the minimum number of kits that must be selected by Bob.-60Input format• The first Ine contains N.• The second line contains y space separated integers denoring the strengen of kies.Output formatPrint the minimum number of kos tat Bob Must seetConsuaintsIN < 105- 50005 Az = 109OPEUS |
|
Answer» java.util.Scanner;public class FiftyPrimes{ // Return true if a number n is prime public static boolean isPrime(long n) { // Check division from 2 to sqrt(n) for (long i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { return false; } } // If no division is found, number is prime return true; } public static void MAIN(String[] args) { // CREATE Scanner object Scanner sc = new Scanner(System.in); // Take user input System.out.print("Enter the starting point: "); long start = sc.nextInt(); // Close Scanner object sc.close(); // If start point is LESS than 2, make it 2 if (start < 2) { start = 2; } int numberOfPrimes = 0; // Number of PRIMES printed long number = start; // Number to be TESTED for prime // Iterate until 50 primes are printed while (numberOfPrimes < 50) { if (isPrime(number)) { System.out.println(number); numberOfPrimes++; } number++; } }} |
|