artemgf

Стенка на стенку

Apr 13th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <algorithm>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int test;
  12.  
  13.     cin >> test;
  14.  
  15.     for (int i = 1; i <= test;i++)
  16.     {
  17.         int n, k;
  18.         cin >> n >> k;
  19.         if (n%k == 0)
  20.             cout << (((n / k)*(n - n / k))*k) / 2 << endl;
  21.         else
  22.             cout << ((((n / k)*(n - n / k))*(k - n%k)) + (n / k + 1)*(n - (n / k + 1))*(n%k)) / 2 << endl;
  23.     }
  24.     _getch();
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment