You are given an integer array nums of length n. An integer k is called sortable if k divides n and you can sort nums in non-decreasing order by sequentially performing the following operations: - Partition nums into consecutive subarrays of length k. - Cyclically rotate each subarray independently any number of times to the left or to the right. Return an integer denoting the sum of all possible sortable integers k.
Example 1
Input: nums = [3,1,2]
Output: 3
Explanation: The divisors of 3 are 1 and 3. Size 1 cannot help because single numbers never move. Size 3 keeps the whole array as one block, which rotates once into [1, 2, 3], so only 3 is sortable and the sum is 3.
Example 2
Input: nums = [7,6,5]
Output: 0
Explanation: The divisors are 1 and 3. Size 1 leaves the array untouched, and the one block [7, 6, 5] has no rotation that is non-decreasing, so no size works and the sum is 0.
Example 3
Input: nums = [5,8]
Output: 3
Explanation: The array is already sorted, so both divisors of 2 work: size 1 needs no change and size 2 keeps it in place. The sum is 1 + 2 = 3.
Rotating a block never moves a value out of it, so each block's contents are frozen; the only non-decreasing array you can reach is the fully sorted one, and a block works for size k only if its target sorted slice is a cyclic rotation of it.
Run checks all cases above. Submit evaluates all test cases.