fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. unsigned long gcd(unsigned long x, unsigned long y) {
  4. return (y!=0) ? gcd(y,x%y) : x;
  5. }
  6.  
  7. int main() {
  8. unsigned int q = 0, p;
  9. cin >> q >> p;
  10. for (unsigned int i = 1; i <= q; i++) {
  11. if((q % i) == 0) {
  12. if (gcd(i,p) == 1)
  13. cout << i << " ";
  14. }
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 0s 15240KB
stdin
40 15
stdout
1 2 4 8