All the multiples of lcmA which are less than or equal to gcdB and evenly divide gcdB will satisfy the conditions
int num = lcmA ; while ( num <= gcdB ) { if ( gcdB % num == 0 ) cout << num << " ▁ " ; num += lcmA ; } }