Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 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) {
  29.         double res = q / p;
  30.  
  31.        
  32.         if (res > 1) {
  33.             for (int i = 1; i <= res; i++) {
  34.                 int b = (int)res % i;
  35.                 if (b == 0) {
  36.                     if (NOD(res / i, i) == 1)
  37.                         count += 1;
  38.                 }
  39.             }
  40.         }
  41.     }
  42.  
  43.     std::cout << count;
  44.     return 0;
  45. }
  46.  
  47.  
  48. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  49. // Debug program: F5 or Debug > Start Debugging menu
  50.  
  51. // Tips for Getting Started:
  52. //   1. Use the Solution Explorer window to add/manage files
  53. //   2. Use the Team Explorer window to connect to source control
  54. //   3. Use the Output window to see build output and other messages
  55. //   4. Use the Error List window to view errors
  56. //   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
  57. //   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