Advertisement
deushiro

why

Nov 25th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <bitset>
  9.  
  10. using namespace std;
  11.  
  12. typedef long long ll;
  13. typedef double d;
  14.  
  15. struct ans{
  16.     d x;
  17.     d m, n;
  18. };
  19.  
  20. bool operator <(ans a, ans b){
  21.     return a.x < b.x;
  22. }
  23.  
  24. int gcd(int v, int u){
  25.     while(v > 0 && u > 0){
  26.         if(v >= u){
  27.             v %= u;
  28.         }
  29.         else
  30.             u %= v;
  31.     }
  32.     return v + u;
  33. }
  34.  
  35. int main() {
  36.     ios_base::sync_with_stdio(false);
  37.     cin.tie(0);
  38.     cout.tie(0);
  39.     int n;
  40.     int p, q;
  41.     double a, b;
  42.     cin >> n >> p >> q;
  43.     a = (d)1 / p;
  44.     b = (d)1 / q;
  45.     vector<ans> res;
  46.     for(d i = 1; i <= n; i += 1){
  47.         for(d j = 1; j <= i; j += 1){
  48.             if(gcd((int)j, (int)i) > 1){
  49.                 continue;
  50.             }
  51.             d v = j / i;
  52.             if(v > a && v < b){
  53.                 res.push_back({v, j, i});
  54.             }
  55.         }
  56.     }
  57.     sort(res.begin(), res.end());
  58.     for(int i = 0; i < res.size(); ++i){
  59.         cout << (int) res[i].m << "/" << (int) res[i].n << endl;
  60.     }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement