Check if the sum of perfect squares in an array is divisible by x | Java implementation of the approach ; Function that returns true if the the sum of all the perfect squares of the given array is divisible by x ; If arr [ i ] is a perfect square ; Driver Code
public class GFG { static boolean check ( int arr [ ] , int x , int n ) { long sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { double y = Math . sqrt ( arr [ i ] ) ; if ( Math . floor ( y ) == Math . ceil ( y ) ) { sum += arr [ i ] ; } } if ( sum % x == 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 9 , 10 } ; int n = arr . length ; int x = 13 ; if ( check ( arr , x , n ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }