Advertisement
Shihab333

Uva 264

Apr 18th, 2015
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5. int f(int x)
  6. {
  7.     x=x*(x+1);
  8.     return x/2;
  9. }
  10. int main()
  11. {
  12.     //freopen("input.txt","r",stdin);
  13.     int n,p=0;
  14.     while(cin>>n) {
  15.         if(p) printf("\n");
  16.         p=1;
  17.         double s=sqrt(1+8*n);
  18.         int i=(1+s)/2;
  19.         if(s*s==1+8*n) i--;
  20.         int start=f(i-1)+1;
  21.         int endd=f(i);
  22.         int r,c;
  23.         r=n-start+1;
  24.         c=i-r+1;
  25.         if(i%2==0) printf("TERM %d IS %d/%d",n,r,c);
  26.         else printf("TERM %d IS %d/%d",n,c,r);
  27.     }
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement