Skip to content

Commit

Permalink
Add 27108.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiyabye committed Aug 8, 2024
1 parent ebbe063 commit c44a8c3
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 27xxx/27108.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
return a.first * b.second < a.second * b.first;
}

void solve(void) {
int n; cin >> n;
vector<pair<int, int>> v;
for (int i=1; i<=n; i++) for (int j=0; j<=i; j++) {
int g = gcd(i, j);
v.push_back({j / g, i / g});
}
sort(v.begin(), v.end(), cmp);
v.erase(unique(v.begin(), v.end()), v.end());

cout << v.size() << "\n";
for (auto &p : v) {
cout << p.first << "/" << p.second << "\n";
}
}

int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);

solve();
return 0;
}

0 comments on commit c44a8c3

Please sign in to comment.