codeparrot/xlcost-text-to-code huggingface dataset:
Count of subarrays which start and end with the same element | Java program to Count total sub - array which start and end with same element ; function to find total sub - array which start and end with same element ; initialize result with 0 ; array to count frequency of 1 to N ; update frequency of A [ i ] ; update result with sub - array contributed by number i ; print the result ; Driver code
public class Main { public static void cntArray ( int A [ ] , int N ) { int result = 0 ; int [ ] frequency = new int [ N + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { frequency [ A [ i ] ] ++ ; } for ( int i = 1 ; i <= N ; i ++ ) { int frequency_of_i = frequency [ i ] ; result += ( ( frequency_of_i ) * ( frequency_of_i + 1 ) ) / 2 ; } System . out . println ( result ) ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 5 , 6 , 1 , 9 , 5 , 8 , 10 , 8 , 9 } ; int N = A . length ; cntArray ( A , N ) ; } }
Length of array pair formed where one contains all distinct elements and other all same elements | Java implementation to Divide the array into two arrays having same size , one with distinct elements and other with same elements ; Function to find the max size possible ; Counting the maximum frequency ; Counting total distinct elements ; Find max of both the answer ; Driver code
import java . io . * ; import java . util . * ; class GFG { static int findMaxSize ( int a [ ] , int n ) { ArrayList < Integer > frq = new ArrayList < Integer > ( n + 1 ) ; for ( int i = 0 ; i <= n ; i ++ ) frq . add ( 0 ) ; for ( int i = 0 ; i < n ; ++ i ) frq . set ( a [ i ] , frq . get ( a [ i ] ) + 1 ) ; int maxfrq = Collections . max ( frq ) ; int dist = n + 1 - Collections . frequency ( frq , 0 ) ; int ans1 = Math . min ( maxfrq - 1 , dist ) ; int ans2 = Math . min ( maxfrq , dist - 1 ) ; int ans = Math . max ( ans1 , ans2 ) ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 4 , 1 , 4 , 3 , 4 } ; int n = arr . length ; System . out . println ( findMaxSize ( arr , n ) ) ; } }
Longest subarray with all elements same | Java program to find largest subarray with all equal elements . ; Function to find largest sub array with all equal elements . ; Traverse the array ; If element is same as previous increment temp value ; Return the required answer ; Driver code ; Function call
import java . util . * ; class GFG { static int subarray ( int arr [ ] , int n ) { int ans = 1 , temp = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { ++ temp ; } else { ans = Math . max ( ans , temp ) ; temp = 1 ; } } ans = Math . max ( ans , temp ) ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 1 , 1 , 2 , 2 , 2 , 3 , 3 } ; int n = arr . length ; System . out . print ( subarray ( arr , n ) ) ; } }
Min and max length subarray having adjacent element difference atmost K | Java program to find the minimum and maximum length subarray such that difference between adjacent elements is atmost K ; Function to find the maximum and minimum length subarray ; Initialise minimum and maximum size of subarray in worst case ; Left will scan the size of possible subarray in left of selected element ; Right will scan the size of possible subarray in right of selected element ; Temp will store size of group associateed with every element ; Loop to find size of subarray for every element of array ; Left will move in left direction and compare difference between itself and element left to it ; Right will move in right direction and compare difference between itself and element right to it ; If subarray of much lesser or much greater is found than yet known then update ; Print minimum and maximum possible size of subarray ; Driver code ; Function call to find maximum and minimum possible sub array
import java . io . * ; import java . util . * ; class GFG { static void findMaxMinSubArray ( int arr [ ] , int K , int n ) { int min = n ; int max = 0 ; int left ; int right ; int tmp ; for ( int i = 0 ; i < n ; i ++ ) { tmp = 1 ; left = i ; while ( left - 1 >= 0 && Math . abs ( arr [ left ] - arr [ left - 1 ] ) <= K ) { left -- ; tmp ++ ; } right = i ; while ( right + 1 <= n - 1 && Math . abs ( arr [ right ] - arr [ right + 1 ] ) <= K ) { right ++ ; tmp ++ ; } if ( min > tmp ) min = tmp ; if ( max < tmp ) max = tmp ; } System . out . print ( min ) ; System . out . print ( " , ▁ " ) ; System . out . print ( max ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 5 , 6 , 7 } ; int K = 2 ; int n = arr . length ; findMaxMinSubArray ( arr , K , n ) ; } }
Count of elements which is the sum of a subarray of the given Array | Java implementation to count the elements such that their exist a subarray whose sum is equal to this element ; Function to count the elements such that their exist a subarray whose sum is equal to this element ; Loop to count the frequency ; Loop to iterate over every possible subarray of the array ; Driver Code
import java . util . * ; class GFG { static int countElement ( int arr [ ] , int n ) { int freq [ ] = new int [ n + 1 ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } for ( int i = 0 ; i < n - 1 ; i ++ ) { int tmpsum = arr [ i ] ; for ( int j = i + 1 ; j < n ; j ++ ) { tmpsum += arr [ j ] ; if ( tmpsum <= n ) { ans += freq [ tmpsum ] ; freq [ tmpsum ] = 0 ; } } } return ans ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; int n = arr . length ; System . out . println ( countElement ( arr , n ) ) ; } }
Nth root of a number using log | Java implementation to find the Kth root of a number using log ; Function to find the Kth root of the number using log function ; Driver Code
import java . util . * ; class GFG { static double kthRoot ( double n , int k ) { return Math . pow ( k , ( ( 1.0 / k ) * ( Math . log ( n ) / Math . log ( k ) ) ) ) ; } public static void main ( String args [ ] ) { double n = 81 ; int k = 4 ; System . out . printf ( " % .6f " , kthRoot ( n , k ) ) ; } }
Make A , B and C equal by adding total value N to them | Java program to distribute integer N among A , B , C such that they become equal ; Find maximum among the three elements ; Summation of three elements ; Check if difference is divisible by 3 ; Driver code
class GFG { static void distributeN ( int A , int B , int C , int n ) { int max1 = Math . max ( A , B ) ; int max2 = Math . max ( B , C ) ; int maximum = Math . max ( max1 , max2 ) ; int sum = A + B + C ; int p = ( 3 * maximum ) - sum ; int diff = n - p ; if ( diff < 0 diff % 3 == 0 ) System . out . print ( " No " ) ; else System . out . print ( " Yes " ) ; } public static void main ( String [ ] args ) { int A = 10 , B = 20 ; int C = 15 , n = 14 ; distributeN ( A , B , C , n ) ; } }
Represent N as sum of K odd numbers with repetitions allowed | Java implementation to represent N as sum of K even numbers ; Function to print the representation ; N must be greater than equal to 2 * K and must be odd ; Driver Code
import java . util . * ; class GFG { static void sumOddNumbers ( int N , int K ) { int check = N - ( K - 1 ) ; if ( check > 0 && check % 2 == 1 ) { for ( int i = 0 ; i < K - 1 ; i ++ ) { System . out . print ( "1 ▁ " ) ; } System . out . print ( + check ) ; } else System . out . println ( " - 1 ▁ " ) ; } public static void main ( String args [ ] ) { int N = 5 ; int K = 3 ; sumOddNumbers ( N , K ) ; } }
Number of continuous reductions of A from B or B from A to make them ( 1 , 1 ) | Java implementation to find the minimum number of operations required to reach ( 1 , 1 ) ; Function to find the minimum number of steps required ; Condition to check if it is not possible to reach ; Condition to check if the pair is reached to 1 , 1 ; Condition to change the A as the maximum element ; Driver Code
class GFG { static int minimumSteps ( int a , int b , int c ) { if ( a < 1 b < 1 ) return - 1 ; if ( a == 1 && b == 1 ) return c ; if ( a < b ) { a = a + b ; b = a - b ; a = a - b ; } return minimumSteps ( a - b , b , c + 1 ) ; } public static void main ( String [ ] args ) { int a = 75 ; int b = 17 ; System . out . println ( minimumSteps ( a , b , 0 ) ) ; } }
Longest Mountain Subarray | Java code for Longest Mountain Subarray ; Function to find the longest mountain subarray ; If the size of array is less than 3 , the array won 't show mountain like  behaviour ; When a new mountain sub - array is found , there is a need to set the variables k , j to - 1 in order to help calculate the length of new mountain sub - array ; j marks the starting index of a new mountain sub - array . So set the value of j to current index i . ; Checks if next element is less than current element ; Checks if starting element exists or not , if the starting element of the mountain sub - array exists then the index of ending element is stored in k ; This condition checks if both starting index and ending index exists or not , if yes , the length is calculated . ; d holds the length of the longest mountain sub - array . If the current length is greater than the calculated length , then value of d is updated . ; Ignore if there is no increase or decrease in the value of the next element ; Checks and calculates the length if last element of the array is the last element of a mountain sub - array ; Driver code
import java . io . * ; class GFG { public static int LongestMountain ( int a [ ] ) { int i = 0 , j = - 1 , k = - 1 , d = 0 ; if ( a . length < 3 ) return 0 ; for ( i = 0 ; i < a . length - 1 ; i ++ ) { if ( a [ i + 1 ] > a [ i ] ) { if ( k != - 1 ) { k = - 1 ; j = - 1 ; } if ( j == - 1 ) j = i ; } else { if ( a [ i + 1 ] < a [ i ] ) { if ( j != - 1 ) k = i + 1 ; if ( k != - 1 && j != - 1 ) { if ( d < k - j + 1 ) d = k - j + 1 ; } } else { k = - 1 ; j = - 1 ; } } } if ( k != - 1 && j != - 1 ) { if ( d < k - j + 1 ) d = k - j + 1 ; } return d ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 1 , 4 , 5 , 6 , 7 , 8 , 9 , 8 , 7 , 6 , 5 } ; System . out . println ( LongestMountain ( a ) ) ; } }
Check whether an Array can be made 0 by splitting and merging repeatedly | Java program for the above approach ; Function that finds if it is possible to make the array contain only 1 element i . e . 0 ; Check if element is odd ; According to the logic in above approach ; Driver code
class GFG { public static String solve ( int [ ] A ) { int i , ctr = 0 ; for ( i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] % 2 == 1 ) { ctr ++ ; } } if ( ctr % 2 == 1 ) { return " No " ; } else { return " Yes " ; } } public static void main ( String [ ] args ) { int [ ] arr = { 9 , 17 } ; System . out . println ( solve ( arr ) ) ; } }
Count of perfect squares of given length | Java Program to count perfect squares of given length ; Function to check if a number is perfect square ; Find floating point value of square root of x . ; If square root is an integer ; Function to return the count of n digit perfect squares ; Initialize result ; Traverse through all numbers of n digits ; Check if current number ' i ' is perfect square ; Driver code
class GFG { static boolean isPerfectSquare ( double x ) { double sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static int countSquares ( int n ) { int cnt = 0 ; for ( int i = ( int ) Math . pow ( 10 , ( n - 1 ) ) ; i < Math . pow ( 10 , n ) ; i ++ ) { if ( i != 0 && isPerfectSquare ( i ) ) cnt ++ ; } return cnt ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( countSquares ( n ) ) ; } }
Count of perfect squares of given length | Java Program to count perfect squares of given length ; Function to return the count of n digit perfect squares ; Driver code
class GFG { static int countSquares ( int n ) { int r = ( int ) Math . ceil ( Math . sqrt ( Math . pow ( 10 , n ) ) ) ; int l = ( int ) Math . ceil ( Math . sqrt ( Math . pow ( 10 , n - 1 ) ) ) ; return r - l ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . print ( countSquares ( n ) ) ; } }
Sum of alternating sign cubes of first N Natural numbers | Java implementation to compute the sum of cubes with alternating sign ; Function to compute sum of the cubes with alternating sign ; Driver code
import java . util . * ; class GFG { static int summation ( int N ) { int co = ( N + 1 ) / 2 ; int ce = ( N ) / 2 ; int se = 2 * ( ( ce * ( ce + 1 ) ) * ( ce * ( ce + 1 ) ) ) ; int so = ( co * co ) * ( 2 * ( ( co * co ) ) - 1 ) ; return so - se ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( summation ( n ) ) ; } }
Program to check if N is a Star Number | Java implementation to check that a number is a star number or not ; Function to check that the number is a star number ; Condition to check if the number is a star number ; Driver code ; Function call
import java . io . * ; import java . util . * ; class GFG { static boolean isStar ( int N ) { double n = ( 6 + Math . sqrt ( 24 * N + 12 ) ) / 6 ; return ( n - ( int ) n ) == 0 ; } public static void main ( String [ ] args ) { int i = 13 ; if ( isStar ( i ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }
Smallest number to make Array sum at most K by dividing each element | Java program to find the smallest number such that the sum of the array becomes less than or equal to K when every element of the array is divided by that number ; Function to find the smallest number such that the sum of the array becomes less than or equal to K when every element of the array is divided by that number ; Binary search between 1 and 10 ^ 9 ; Calculating the new sum after dividing every element by mid ; If after dividing by mid , if the new sum is less than or equal to limit move low to mid + 1 ; Else , move mid + 1 to high ; Returning the minimum number ; Driver Code
import java . util . * ; class GFG { static int findMinDivisor ( int arr [ ] , int n , int limit ) { int low = 0 , high = 1000000000 ; while ( low < high ) { int mid = ( low + high ) / 2 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += Math . ceil ( ( double ) arr [ i ] / ( double ) mid ) ; } if ( sum <= limit ) high = mid ; else low = mid + 1 ; } return low ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 3 , 4 , 9 } ; int N = arr . length ; int K = 6 ; System . out . println ( findMinDivisor ( arr , N , K ) ) ; } }
Count of triplets ( a , b , c ) in the Array such that a divides b and b divides c | Java program to find count of triplets ( a , b , c ) in the Array such that a divides b and b divides c ; Function to count triplets ; Iterate for middle element ; Iterate left array for a [ i ] ; Iterate right array for a [ k ] ; return the final result ; Driver code
import java . io . * ; import java . util . * ; class GFG { static int getCount ( int arr [ ] , int n ) { int count = 0 ; for ( int j = 1 ; j < n - 1 ; j ++ ) { int p = 0 , q = 0 ; for ( int i = 0 ; i < j ; i ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) p ++ ; } for ( int k = j + 1 ; k < n ; k ++ ) { if ( arr [ k ] % arr [ j ] == 0 ) q ++ ; } count += p * q ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 } ; int N = arr . length ; System . out . println ( getCount ( arr , N ) ) ; } }
Find pair with maximum ratio in an Array | Java implementation to find the maximum pair in the array ; Function to find the maximum pair possible for the array ; Loop to iterate over every possible pair in the array ; Check pair ( x , y ) as well as ( y , x ) for maximum value ; Update the answer ; Driver code
import java . io . * ; import java . util . * ; class GFG { static float computeMaxValue ( float arr [ ] , int n ) { float ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { float val = Math . max ( arr [ i ] / arr [ j ] , arr [ j ] / arr [ i ] ) ; ans = Math . max ( ans , val ) ; } } return ans ; } public static void main ( String [ ] args ) { float arr [ ] = { 15 , 10 , 3 , 2 } ; int N = arr . length ; System . out . println ( computeMaxValue ( arr , N ) ) ; } }
Find the Kth number which is not divisible by N | Java implementation to find the K 'th non-divisible number of N ; Function to find the Kth not divisible by N ; Driver Code ; Function Call
class GFG { static int kthNonDivisible ( int N , int K ) { return ( int ) ( K + Math . floor ( ( K - 1 ) / ( N - 1 ) ) ) ; } public static void main ( String [ ] args ) { int N = 3 ; int K = 6 ; System . out . print ( kthNonDivisible ( N , K ) ) ; } }
Find the maximum sum pair in an Array with even parity | Java implementation to find a pair with even parity and maximum sum ; Function that returns true if count of set bits in given number is even ; Parity will store the count of set bits ; Function to print the elements of the array ; Function to remove all the even parity elements from the given array ; Traverse the array ; If the current element has even parity ; Driver Code ; Function Call
import java . util . * ; class GFG { static int sz = ( int ) 1e3 ; static boolean isEvenParity ( int x ) { int parity = 0 ; while ( x != 0 ) { if ( x % 2 == 1 ) parity ++ ; x = x >> 1 ; } if ( parity % 2 == 0 ) return true ; else return false ; } static void printArray ( int arr [ ] , int len ) { for ( int i = 0 ; i < len ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } static void findPairEvenParity ( int arr [ ] , int len ) { int firstMaximum = Integer . MIN_VALUE ; int secondMaximum = Integer . MIN_VALUE ; for ( int i = 0 ; i < len ; i ++ ) { if ( isEvenParity ( arr [ i ] ) ) { if ( arr [ i ] >= firstMaximum ) { secondMaximum = firstMaximum ; firstMaximum = arr [ i ] ; } else if ( arr [ i ] >= secondMaximum ) { secondMaximum = arr [ i ] ; } } } System . out . print ( firstMaximum + " ▁ " + secondMaximum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 18 , 15 , 8 , 9 , 14 } ; int len = arr . length ; findPairEvenParity ( arr , len ) ; } }
Program to check if N is a Hexagonal Number or not | Java program to check if N is a hexagonal number ; Function to check if number is hexagonal ; Calculate the value for n ; Check if n - floor ( n ) is equal to 0 ; Driver code
import java . util . * ; class GFG { static boolean isHexagonal ( int N ) { float val = 8 * N + 1 ; float x = 1 + ( float ) Math . sqrt ( val ) ; float n = ( x ) / 4 ; if ( ( n - ( int ) n ) == 0 ) return true ; else return false ; } public static void main ( String [ ] args ) { int N = 14 ; if ( isHexagonal ( N ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Program to convert Number in characters | Java program to convert number in characters ; To calculate the reverse of the number ; The remainder will give the last digit of the number ; Extract the first digit of the reversed number ; Match it with switch case ; Divide the number by 10 to get the next number ; Driver code
class GFG { static void NumbertoCharacter ( int n ) { int rev = 0 , r = 0 ; while ( n > 0 ) { r = n % 10 ; rev = rev * 10 + r ; n = n / 10 ; } while ( rev > 0 ) { r = rev % 10 ; switch ( r ) { case 1 : System . out . print ( " one ▁ " ) ; break ; case 2 : System . out . print ( " two ▁ " ) ; break ; case 3 : System . out . print ( " three ▁ " ) ; break ; case 4 : System . out . print ( " four ▁ " ) ; break ; case 5 : System . out . print ( " five ▁ " ) ; break ; case 6 : System . out . print ( " six ▁ " ) ; break ; case 7 : System . out . print ( " seven ▁ " ) ; break ; case 8 : System . out . print ( " eight ▁ " ) ; break ; case 9 : System . out . print ( " nine ▁ " ) ; break ; case 0 : System . out . print ( " zero ▁ " ) ; break ; default : System . out . print ( " UnValid ▁ " ) ; break ; } rev = rev / 10 ; } } public static void main ( String [ ] args ) { int n = 12345 ; NumbertoCharacter ( n ) ; } }
Count all subarrays whose sum can be split as difference of squares of two Integers | Java program to count all the non - contiguous subarrays whose sum can be split as the difference of the squares ; Function to count all the non - contiguous subarrays whose sum can be split as the difference of the squares ; Loop to iterate over all the possible subsequences of the array ; Finding the sum of all the possible subsequences ; Condition to check whether the number can be split as difference of squares ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int Solve ( int arr [ ] , int n ) { int temp = 0 , count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { temp = 0 ; for ( int j = i ; j < n ; j ++ ) { temp += arr [ j ] ; if ( ( temp + 2 ) % 4 != 0 ) count ++ ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int N = arr . length ; System . out . println ( Solve ( arr , N ) ) ; } }
Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M | Java program to find the product of all the combinations of M elements from an array whose index in the sorted order divides M completely ; Iterative Function to calculate ( x ^ y ) % p in O ( log y ) ; If y is odd , multiply x with result ; y must be even now ; Iterative Function to calculate ( nCr ) % p and save in f [ n ] [ r ] C ( n , r ) % p = [ C ( n - 1 , r - 1 ) % p + C ( n - 1 , r ) % p ] % p and C ( n , 0 ) = C ( n , n ) = 1 ; If j > i then C ( i , j ) = 0 ; If i is equal to j then C ( i , j ) = 1 ; C ( i , j ) = ( C ( i - 1 , j ) + C ( i - 1 , j - 1 ) ) % p ; Initialize the answer ; For every element arr [ i ] , x is count of occurrence of arr [ i ] in different set such that index of arr [ i ] in those sets divides m completely . ; Finding the count of arr [ i ] by placing it at the index which divides m completely ; Using fermat 's little theorem ; Multiplying with the count ; Driver code
import java . util . * ; class GFG { static int m = 4 ; static long power ( long x , long y , long p ) { long res = 1 ; x = x % p ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static void nCr ( int n , long p , int f [ ] [ ] ) { for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= m ; j ++ ) { if ( j > i ) f [ i ] [ j ] = 0 ; else if ( j == 0 j == i ) f [ i ] [ j ] = 1 ; else f [ i ] [ j ] = ( f [ i - 1 ] [ j ] + f [ i - 1 ] [ j - 1 ] ) % ( int ) p ; } } } static void operations ( int arr [ ] , int n , int f [ ] [ ] ) { long p = 1000000007 ; nCr ( n , p - 1 , f ) ; Arrays . sort ( arr ) ; long ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { long x = 0 ; for ( int j = 1 ; j <= m ; j ++ ) { if ( m % j == 0 ) x = ( x + ( f [ n - i - 1 ] [ m - j ] * f [ i ] [ j - 1 ] ) % ( p - 1 ) ) % ( p - 1 ) ; } ans = ( ( ans * power ( arr [ i ] , x , p ) ) % p ) ; } System . out . print ( ans + "NEW_LINE"); } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 7 , 9 , 3 } ; int n = arr . length ; int [ ] [ ] f = new int [ n + 1 ] [ m + 1 ] ; operations ( arr , n , f ) ; } }
Check whether a number can be represented by the product of two squares | Java implementation to check whether a number can be represented by the product of two squares ; Function to check if there exist two numbers product of whose squares is n . ; Check whether the product of the square of both numbers is equal to N ; Driver code
class GFG { static boolean prodSquare ( int n ) { for ( long i = 2 ; i * i <= n ; i ++ ) for ( long j = 2 ; j <= n ; j ++ ) if ( i * i * j * j == n ) return true ; return false ; } public static void main ( String [ ] args ) { int n = 25 ; if ( prodSquare ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }