fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<map>
  6. #include<math.h>
  7. const long long inf=1e17;
  8.  
  9. #define forn(i,n) for(int i=0;i<n;i++)
  10. #define ll long long
  11. using namespace std;
  12. ll mod=pow(10,9)+7;
  13. int main()
  14. {
  15. int t;
  16. ll x,n,p;
  17. scanf("%d",&t);
  18. while(t--)
  19. {
  20.  
  21. scanf("%lld",&x);
  22. n=ceil((-1+sqrt(8*x+1))/2);
  23. p = x - n*(n-1)/2;
  24. if (n%2==0)
  25. printf("TERM %lld IS %lld/%lld\n",x , p , n+1-p);
  26. else
  27. printf("TERM %lld IS %lld/%lld\n",x, n + 1 -p ,p);
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 3100KB
stdin
3
3
14
7
stdout
TERM 3 IS 2/1
TERM 14 IS 2/4
TERM 7 IS 1/4