Find the count of prime factors of b using distinct prime factors of a
foreach ( KeyValuePair < int , int > m in ma ) { int cnt = 0 ; int key = m . Key ; int value = m . Value ; while ( b % key == 0 ) { b /= key ; cnt ++ ; }