artemgf

Сумма последовательных чисел

Apr 15th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <set>
  6. #include <map>
  7. #include <algorithm>
  8. #include <string>
  9. #include <math.h>
  10. #include <vector>
  11. #include <cmath>
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17.     long long n, A, P, p=1, a;
  18.     bool what = false;
  19.  
  20.     cin >> n;
  21.  
  22.     while (2 * n - p*p + p>0)
  23.     {
  24.         if ((2 * n - p*p + p) % (2 * p) == 0)
  25.         {
  26.             P = p;
  27.             A = (2 * n - p*p + p) / (2 * p);
  28.  
  29.         }
  30.         p++;
  31.     }
  32.     cout << A << " " << P;
  33.  
  34.     _getch();
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment