原題鏈接
#include#include int main(){ int m, n, x, y, t; scanf("%d", &m); while(m--){ scanf("%d", &n); x = 0; y = 1; for(int i = 1; (t = (1 + i) * i / 2) < n; ++i) x = i, y = n - t; x += 2; if(x & 1) printf("%d/%d\n", y, x - y); else printf("%d/%d\n", x - y, y); } return 0; }
#include#include main() { int n,m,x,y; scanf("%d\n",&m); while(m--) { scanf("%d",&n); x=(int)(sqrt(2*n)-0.5); y=n-x*(x+1)/2; if(x%2==0) printf("%d/%d\n",x+2-y,y); else printf("%d/%d\n",y,x+2-y); } }