Advertisement
a53

sotron

a53
Jan 31st, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <fstream>
  2. #define InFile "sotron.in"
  3. #define OutFile "sotron.out"
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int p,n;
  9. long long m,C,s;
  10. ifstream f(InFile);
  11. f>>p>>n>>m;
  12. f.close();
  13. ofstream g(OutFile);
  14. if(p==1)
  15. g<<1ULL*n*(n+1)/2<<'\n';
  16. else
  17. {
  18. int i,r,c=0;
  19. s=0;
  20. for(i=n;i;i-=2)
  21. {
  22. ++c;
  23. s+=2*i-1;
  24. if(s>=m)
  25. break;
  26. }
  27. C=s-i+1;
  28. if(m>C)
  29. r=n-c+1,c=c+m-C;
  30. else
  31. r=(n-c+1)-(C-m);
  32. g<<r<<' '<<c<<'\n';
  33. }
  34. g.close();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement