Advertisement
OIQ

U

OIQ
Nov 25th, 2019
184
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None
  1. #include <iostream>
  2. #include <set>
  3. #include <vector>
  4. #include <utility>
  5. #include <algorithm>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. int gcd(int a, int b) {
  11.     return b ? gcd(b, a % b) : a;
  12. }
  13.  
  14. int main() {
  15.     vector <pair<double, string>> a;
  16.     double n, p, q;
  17.  
  18.     cin >> n >> p >> q;
  19.  
  20.     set<double> s;
  21.  
  22.     for (double j = n; j >= 1; j--) {
  23.         for (double i = 1; i <= n; i++) {
  24.             int d = gcd(i, j);
  25.             double i1 = i / d;
  26.             double j1 = j / d;
  27.             if (1 / p < i1 / j1 && i / j1 < 1 / q && s.find(i1 / j1) == s.end()) {
  28.                 s.insert(i1 / j1);
  29.                 int n1 = i1;
  30.                 int n2 = j1;
  31.                 a.push_back(pair<double, string>(i1 / j1, to_string(n1) + "/" + to_string(n2)));
  32.             }
  33.         }
  34.     }
  35.  
  36.     sort(a.begin(), a.end());
  37.  
  38.     for (int i = 0; i < a.size(); i++)
  39.         cout << a[i].second << endl;
  40.     return 0;
  41. }
Advertisement
RAW Paste Data Copied
Advertisement