You are given an integer array nums.
An array is considered alternating prime if:
In one operation, you may increment any element by 1.
Return the minimum number of operations required to transform nums into an alternating prime array.
A prime number is a natural number greater than 1 with only two factors, 1 and itself.
Example 1:
Input: nums = [1,2,3,4]
Output: 3
Explanation:
nums[0] = 1 to 2, using 1 operation.nums[1] = 2 to 4, using 2 operations.Total operations = 1 + 2 = 3.
Example 2:
Input: nums = [5,6,7,8]
Output: 0
Explanation:
No operations are needed.
Example 3:
Input: nums = [4,4]
Output: 1
Explanation:
nums[0] = 4 to 5, using 1 operation.Total operations = 1.
Constraints:
1 <= nums.length <= 1051 <= nums[i] <= 105Loading editor...
[1,2,3,4]