jakaria_hossain

lightoj - 1008 - Fibsieve`s Fantabulous Birthday

Jul 31st, 2019
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6. int t,ca;
  7. cin>>t;
  8. for(ca=1; ca<=t; ca++)
  9. {
  10. ll s,sq,c;
  11. cin>>s;
  12. sq=sqrt(s);
  13. if(sq*sq==s)
  14. {
  15. if(sq%2)
  16. cout<<"Case "<<ca<< ": "<<1<< " "<<sq<<endl;
  17. else
  18. cout<<"Case "<<ca<< ": "<<sq<< " "<<1<<endl;
  19. }
  20. else
  21. {
  22. if(sq%2==0)
  23. {
  24. ll r = sq+1;
  25. ll ind = r*r;
  26.  
  27. if(s>=ind-r+1)
  28. {
  29. c = ind - s + 1;
  30. }
  31.  
  32. else
  33. {
  34. c = sq+1;
  35. ll Minus = ind - r + 1 - s;
  36. r-= Minus;
  37.  
  38. }
  39. cout<<"Case "<<ca<< ": "<<c<<" "<<r<<endl;
  40. }
  41.  
  42. else
  43. {
  44. ll r, ind = (sq+1)*(sq+1);
  45. ll f = sq+1;
  46. if(s>=ind-f+1)
  47. {
  48. c = f;
  49. ll Plus = ind - s ;
  50. r = Plus + 1;
  51. }
  52. else
  53. {
  54. r = f;
  55. ll q = ind - f + 1 - s ;
  56. c = f - q;
  57. }
  58. cout<<"Case "<<ca<< ": "<<c<<" "<<r<<endl;
  59. }
  60.  
  61. }
  62. }
  63. }
RAW Paste Data