Company: Talent Next Exam

Difficulty: easy

Problem Statement

Sum of Non-Prime Index Values A prime number is a natural number greater than 1 whose only positive divisors are 1 and itself. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 . You are given an array of N integers. Find the sum of the values stored at the non-prime indexes of the array. The array is 0-indexed : the position (index) of the first element is 0 , the position of the next element is 1 , and so on. An index is a non-prime index when the index itself is not a prime number. In particular, 0 and 1 are not prime numbers, so index 0 and index 1 are both non-prime indexes and the values stored there are included in the sum. Input Format The first line contains a single integer N , the number of elements in the array. The second line contains N space-separated integers, the elements of the array. Output Format Print a single integer: the sum of the values at the non-prime indexes of the array. Constraints 1 <= N <= 20000 -10000 <= array[i] <= 10000 Fu

More Talent Next Exam OA questionsInterview experiences