fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define debug(val) printf("check%d\n",val)
  5. #define all(v) v.begin(),v.end()
  6. #define PB push_back
  7. #define MP make_pair
  8. #define FF first
  9. #define SS second
  10. #define ll long long
  11. #define MOD 1000000007
  12. #define clr(val) memset(val,0,sizeof(val))
  13. #define what_is(x) cerr << #x << " is " << x << endl;
  14. #define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  15.  
  16. ll nC2(ll n){
  17. return n*(n-1)/2;
  18. }
  19. int main()
  20. {
  21. #ifndef ONLINE_JUDGE
  22. // for getting input from input.txt
  23. freopen("input.txt", "r", stdin);
  24. // for writing output to output.txt
  25. freopen("output.txt", "w", stdout);
  26. #endif
  27.  
  28. FIO
  29. ll n,m;
  30. cin>>n>>m;
  31. ll rem=n%m;
  32. ll div=n/m;
  33. ll kmin,kmax;
  34.  
  35. kmax=(n-m+1)*(n-m)/2;
  36. if(rem!=0){
  37. kmin= (nC2(rem) + ((m-1)*(nC2((n+rem))/m)));
  38. }
  39. else kmin= m*nC2(div);
  40.  
  41. cout<<kmin<<" "<<kmax<<endl;
  42.  
  43. return 0;
  44.  
  45. }
Success #stdin #stdout 0s 4380KB
stdin
Standard input is empty
stdout
0 1580096592889797352