Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdlib.h>
  4. long int gcd(long int m,long int n)
  5. {
  6. if(n==0)
  7. {
  8. return m;
  9. }
  10. return gcd(n,m%n);
  11. }
  12. int comDiv(long int x,long int y)
  13. {
  14. long int g,c=0;
  15. if(x==y)
  16. {
  17. g=x;
  18. }
  19. if(x<y)
  20. {
  21. g=gcd(y,x);
  22. }
  23. else
  24. {
  25. g=gcd(x,y);
  26. }
  27. for(int i=1;i<=sqrt(g);i++)
  28. {
  29. if(g%i==0)
  30. {
  31. if(g/i==i)
  32. {
  33. c+=1;
  34. }
  35. else
  36. {
  37. c+=2;
  38. }
  39. }
  40. }
  41. return c;
  42. }
  43. int main()
  44. {
  45. long int n,x,y,result;
  46. scanf("%ld",&n);
  47. for(int i=0;i<n;i++)
  48. {
  49. scanf("%ld%ld",&x,&y);
  50. result=comDiv(x,y);
  51. printf("%ld",result);
  52. }
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement