Advertisement
Anik_Akash

1008 - Fibsieve`s Fantabulous Birthday

Aug 21st, 2020
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. //thanks God For Every Thing!
  2. //contest link:
  3. #include<bits/stdc++.h>
  4. #define pi           acose(-1)
  5. #define flush        cin.ignore(numeric_limits<streamsize>::max(),'\n');
  6. #define wow          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  7. #define max          170000
  8.  
  9. typedef long long int           ll;
  10. typedef double                  dl;
  11.  
  12. using namespace std;
  13.  
  14. int main()
  15. {
  16.     ll n, t, i=1;
  17.     ll root, mid, cil, flr, row, col;
  18.     wow
  19.     cin>>t;
  20.     while(t--)
  21.     {
  22.         cin>>n;
  23.         root = sqrt(n);
  24.         if(root*root==n)
  25.         {
  26.             if(root%2==0)
  27.             {
  28.                 printf("Case %lld: %lld 1\n",i, root);
  29.                 i++;
  30.             }
  31.             else
  32.             {
  33.                 printf("Case %d: 1 %lld\n",i, root);
  34.                 i++;
  35.             }
  36.         }
  37.         else
  38.         {
  39.             dl  nw_root;
  40.             nw_root = sqrt(n);
  41.             cil = ceil(nw_root);
  42.             flr = floor(nw_root);
  43.             mid = ((cil*cil)+((flr*flr)+1))/2;
  44.             if(mid==n)
  45.             {
  46.                 printf("Case %d: %lld %lld\n",i, cil, cil);
  47.                 i++;
  48.             }
  49.             else if(cil*cil>n && n>mid)
  50.             {
  51.                 row = cil;
  52.                 col = (cil*cil-n+1);
  53.                 printf("Case %d: %lld %lld\n",i, col, row);
  54.                 i++;
  55.             }
  56.  
  57.         }
  58.     }
  59.     i=1;
  60.     return 0;
  61. }
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement