fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. int q = 0, p;
  10. Scanner in = new Scanner(System.in);
  11.  
  12. q = in.nextInt();
  13. p = in.nextInt();
  14.  
  15. for (int i = 1; i <= q; i++) {
  16. if((q % i) == 0) {
  17. if (gcd(i,p) == 1)
  18. System.out.print(i + " ");
  19. }
  20. }
  21. }
  22. public static long gcd(long x, long y) {
  23. return (y!=0) ? gcd(y,x%y) : x;
  24. }
  25. }
Success #stdin #stdout 0.07s 4386816KB
stdin
40 15
stdout
1 2 4 8