Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. // ConsoleApplication4.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4.  
  5. #include <iostream>
  6.  
  7. int NOD(int a, int b)
  8. {
  9.     while (a > 0 && b > 0)
  10.  
  11.         if (a > b)
  12.             a %= b;
  13.  
  14.         else
  15.             b %= a;
  16.  
  17.     return a + b;
  18. }
  19.  
  20. int main()
  21. {
  22.  
  23.     int p, q;
  24.  
  25.     std::cin >> p >> q;
  26.     int count = 0;
  27.  
  28.     if (p > 0 && q > 0) {
  29.  
  30.         double res = q / p;
  31.         double r = q % p;
  32.  
  33.         if (r == 0 && res > 0) {
  34.             for (int i = 1; i <= res; i++) {
  35.                 int b = (int)res % i;
  36.                 if (b == 0) {
  37.                     if (NOD(res / i, i) == 1)
  38.                         count += 1;
  39.                 }
  40.             }
  41.         }
  42.     }
  43.  
  44.  
  45.     std::cout << count;
  46.     return 0;
  47.  
  48. }
  49.  
  50. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  51. // Debug program: F5 or Debug > Start Debugging menu
  52.  
  53. // Tips for Getting Started:
  54. //   1. Use the Solution Explorer window to add/manage files
  55. //   2. Use the Team Explorer window to connect to source control
  56. //   3. Use the Output window to see build output and other messages
  57. //   4. Use the Error List window to view errors
  58. //   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  59. //   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement