Number of Co | C # program to count the pairs whose sum of digits is co - prime ; Function to find the elements after doing the sum of digits ; Traverse from a to b ; Find the sum of the digits of the elements in the given range one by one ; Function to count the co - prime pairs ; Function to make the pairs by doing the sum of digits ; Count pairs that are co - primes ; Driver code ; Function to count the pairs
using System ; using System . Collections . Generic ; class GFG { public static int GCD ( int a , int b ) { if ( b == 0 ) { return a ; } return GCD ( b , a % b ) ; } public static void makePairs ( List < int > pairs , int a , int b ) { for ( int i = a ; i <= b ; i ++ ) { int sumOfDigits = 0 , k = i ; while ( k > 0 ) { sumOfDigits += k % 10 ; k /= 10 ; } if ( sumOfDigits <= 162 ) { pairs . Add ( sumOfDigits ) ; } } } public static int countCoPrime ( int a , int b ) { List < int > pairs = new List < int > ( ) ; makePairs ( pairs , a , b ) ; int count = 0 ; for ( int i = 0 ; i < pairs . Count ; i ++ ) { for ( int j = i + 1 ; j < pairs . Count ; j ++ ) { if ( GCD ( pairs [ i ] , pairs [ j ] ) == 1 ) { count ++ ; } } } return count ; } public static void Main ( string [ ] args ) { int a = 12 , b = 15 ; Console . WriteLine ( countCoPrime ( a , b ) ) ; } }