Tap here to switch tabs
Problem
Submissions

Problem: Split Array by Prime Indices

Try to solve the Split Array by Prime Indices problem.

Statement

You are given an integer array nums.

Split the elements of nums into two groups according to their indices:

  • An array A containing each element nums[i] where index i is a prime number.

  • An array B containing each element nums[i] where index i is not a prime number.

Return the absolute difference between the sum of the elements in A and the sum of the elements in B.

Note: An integer p>1p > 1 is a prime number if its only positive divisors are 11 and pp. The numbers 00 and 11 are not prime numbers.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Split Array by Prime Indices

Try to solve the Split Array by Prime Indices problem.

Statement

You are given an integer array nums.

Split the elements of nums into two groups according to their indices:

  • An array A containing each element nums[i] where index i is a prime number.

  • An array B containing each element nums[i] where index i is not a prime number.

Return the absolute difference between the sum of the elements in A and the sum of the elements in B.

Note: An integer p>1p > 1 is a prime number if its only positive divisors are 11 and pp. The numbers 00 and 11 are not prime numbers.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −109≤-10^9 \leq nums[i] ≤109\leq 10^9