P1014 [NOIP1999 普及组] Cantor 表(模拟/枚举)
https://www.luogu.com.cn/problem/P1014
详解见代码内部注释部分
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=2850,M=4002;
const double PI=3.1415926535;
LL a[N];
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
LL T=1;
//cin>>T;
while(T--)
{
LL n;
cin>>n;
LL k=1;
while(n>k)
{
n-=k;
k++;
}
//第一层往右 3 (奇数往左)
//第二层往左 4 (偶数往右)
if(k%2==1) cout<<k+1-n<<"/"<<n<<endl;
else cout<<n<<"/"<<k+1-n<<endl;
}
return 0;
}