Given an array arr of size N which contains at least one composite number. The task is to find out the sum of all the composite numbers in the array which are at odd indices (where indexing is 1 based).
Input: arr = [13, 5, 8, 16, 25]
The number in the odd indices are 13, 8, 25 since we follow 1 based indexing.
Out of all these 3 numbers, the composite numbers are 8 and 25, which sums to 33.
Input: arr = [9, 7, 14, 10, 34]
The number in the odd indices are 9, 14, 34 since we follow 1 based indexing.
All three numbers are composite numbers, which sums to 57.
To solve the problem mentioned above the main idea is to check for the composite numbers that is, if an integer has more than 2 factors then it’s a composite number otherwise it is not. Then we will iterate and check for the composite numbers in odd indices of the array. If it is a composite number then we will add it to the sum variable otherwise skip it until the end of the array reaches.
Below is the implementation of the above approach:
- Bitwise AND of the sum of prime numbers and the sum of composite numbers in an array
- Product of all the Composite Numbers in an array
- Sum and Product of all Composite numbers which are divisible by k in an array
- XOR of K smallest prime and composite numbers from the given array
- XOR of K largest prime and composite numbers from the given array
- Sum and product of k smallest and k largest composite numbers in the array
- Sum of all composite numbers lying in the range [L, R] for Q queries
- Queries for the difference between the count of composite and prime numbers in a given range
- Find the GCD of N Fibonacci Numbers with given Indices
- Sum of elements in an array having composite frequency
- Count and Sum of composite elements in an array
- Magical Indices in an array
- Find all good indices in the given Array
- Count of indices in an array that satisfy the given condition
- Reverse the substrings of the given String according to the given Array of indices
- Reorder an Array according to given indices with repetition allowed
- Check if the array can be sorted using swaps between given indices only
- Find the count of unvisited indices in an infinite array
- Count the pairs in an array such that the difference between them and their indices is equal
- Range sum queries for anticlockwise rotations of Array by K indices