Lucian_Adrian

#2013 numere18

Oct 5th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. ifstream istr ("numere18.in");
  4. ofstream ostr ("numere18.out");
  5. int main ()
  6. {
  7. int n,m,c;
  8. istr >> c;
  9. int x=1;
  10. if (c == 1)
  11. {
  12. istr >> n;
  13. int s=0, a = n * (n - 1)/2 , b = n * (n + 1)/2;
  14. for (int i = a + 1; i <= b ; ++i)
  15. s=s+i;
  16. ostr << s;
  17.  
  18. }
  19.  
  20. if (c == 2)
  21. {
  22. istr >> m;
  23. int k=1;
  24. while (k * (k + 1)/2 < m) k++;
  25. k--;
  26. ostr << k+1<< ' ' << m - k* (k+1)/2;
  27. }
  28. istr.close ();
  29. ostr.close ();
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment