Check if product of array containing prime numbers is a perfect square | C # implementation of the approach ; Function that returns true if the product of all the array elements is a perfect square ; Update the frequencies of all the array elements ; If frequency of some element in the array is odd ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool isPerfectSquare ( int [ ] arr , int n ) { Dictionary < int , int > umap = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( umap . ContainsKey ( arr [ i ] ) ) umap [ arr [ i ] ] ++ ; else umap [ arr [ i ] ] = 1 ; } Dictionary < int , int > . ValueCollection valueColl = umap . Values ; foreach ( int val in valueColl ) { if ( val % 2 == 1 ) return false ; } return true ; } public static void Main ( ) { int [ ] arr = { 2 , 2 , 7 , 7 } ; int n = arr . Length ; if ( isPerfectSquare ( arr , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }