大佬求助!!!
查看原帖
大佬求助!!!
1063799
chenshenqi楼主2024/3/24 12:21
#include <bits/stdc++.h>
using namespace std;
struct node{
	int x,y;
}a[100005];
bool cmp(node a,node b){
	return (a.x*1.0)/(a.y*1.0)<(b.x*1.0)/(b.y*1.0);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << "0/1\n";
    int n;
    cin >> n;
    int k=0;
    for (int i=1; i<=n; i++){//fenmu
		for (int j=1; j<i; j++){//fenzi
			if (__gcd(i,j)==1){
				a[k].x=j;
				a[k].y=i;
				k++;
			}
		}
	}
	sort(a,a+n,cmp);
	for (int i=0; i<k; i++){
		cout << a[i].x << "/" << a[i].y << endl;
	}
	return 0;
}

2024/3/24 12:21
加载中...