Advertisement
Robert_JR

1008 - Fibsieve`s Fantabulous Birthday

Sep 23rd, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8.  
  9. int main()
  10. {
  11.     int t_case, t = 1;
  12.     cin >> t_case;
  13.     long long int col, row, max, min, mid, temp,num;
  14.     while(t_case--)
  15.     {
  16.         cin >> num;
  17.         if(num == 1)
  18.         {
  19.             printf("Case %d: ", t++);
  20.             cout << 1 << ' ' << 1 << endl;
  21.         }
  22.         else
  23.         {
  24.             temp = ceil(sqrt(num));
  25.             max = temp*temp;
  26.             min = (max - ((temp*2) - 2));
  27.             mid = (max+min) / 2;
  28.             if(!(max & 1))
  29.             {
  30.                 if(num < mid)
  31.                 {
  32.                     col = (num - min)+1;
  33.                     row = temp;
  34.                 }
  35.                 else if(num > mid)
  36.                 {
  37.                     col = temp;
  38.                     row = (max - num)+1;
  39.                 }
  40.                 else
  41.                 {
  42.                     col = row = temp;
  43.                 }
  44.             }
  45.             else
  46.             {
  47.                 if(num < mid)
  48.                 {
  49.                     row = (num - min)+1;
  50.                     col = temp;
  51.                 }
  52.                 else if(num > mid)
  53.                 {
  54.                     row = temp;
  55.                     col = (max - num)+1;
  56.                 }
  57.                 else
  58.                 {
  59.                     col = row = temp;
  60.                 }
  61.             }
  62.             printf("Case %d: %lld %lld\n", t++, col, row);
  63.  
  64.         }
  65.     }
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement