Iterate through all the substrings
for i in range ( n ) : NEW_LINE INDENT for j in range ( i , n , 1 ) : NEW_LINE INDENT if ( i - 1 >= 0 ) : NEW_LINE INDENT countOfOnes = prefix_sum [ j ] - prefix_sum [ i - 1 ] NEW_LINE DEDENT else : NEW_LINE INDENT countOfOnes = prefix_sum [ j ] NEW_LINE DEDENT length = j - i + 1 NEW_LINE if ( countOfOnes > 0 and length % countOfOnes == 0 ) : NEW_LINE INDENT answer += 1 NEW_LINE DEDENT DEDENT DEDENT return answer NEW_LINE