Check if the sum of perfect squares in an array is divisible by x | C # 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
using System ; public class GFG { static bool 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 . Ceiling ( y ) ) { sum += arr [ i ] ; } } if ( sum % x == 0 ) return true ; else return false ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 9 , 10 } ; int n = arr . Length ; int x = 13 ; if ( check ( arr , x , n ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }