Count of pairs ( i , j ) in the array such that arr [ i ] is a factor of arr [ j ] | Java Program to find the number of pairs ( i , j ) such that arr [ i ] is a factor of arr [ j ] ; Function to return the count of Pairs ; Driver code
import java . util . * ; import java . lang . * ; class GFG { static int numPairs ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] % arr [ i ] == 0 ) ans ++ ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 , 2 , 3 , 3 } ; int n = arr . length ; System . out . println ( numPairs ( arr , n ) ) ; } }