Subarrays whose sum is a perfect square | Python3 program to implement the above approach ; Function to print the start and end indices of all subarrays whose sum is a perfect square ; Stores the current subarray sum ; Update current subarray sum ; Stores the square root of currSubSum ; Check if currSubSum is a perfect square or not ; Driver Code
import math NEW_LINE def PrintIndexes ( arr , N ) : NEW_LINE INDENT for i in range ( N ) : NEW_LINE INDENT currSubSum = 0 NEW_LINE for j in range ( i , N , 1 ) : NEW_LINE INDENT currSubSum += arr [ j ] NEW_LINE sq = int ( math . sqrt ( currSubSum ) ) NEW_LINE if ( sq * sq == currSubSum ) : NEW_LINE INDENT print ( " ( " , i , " , " , j , " ) " , end = " ▁ " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT arr = [ 65 , 79 , 81 ] NEW_LINE N = len ( arr ) NEW_LINE PrintIndexes ( arr , N ) NEW_LINE