Codeforces478 B. Random Teams (Mathematics)

Title:


Divide N people into M groups with at least one person in each group. At the end of the game, people in the same group will become friends in pairs, and the number of pairs of friends will be different for different grouping schemes.
Your task is to find the smallest and largest friend logarithm.

Data range: m<=n<=1e9

solution:

ma:(m-1)组只有一个人,剩下一组n-(m-1)个人

mi:
平均分成m组即可

code:

#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
    
    
    ios::sync_with_stdio(0);
    int n,m;cin>>n>>m;
    int ma=0,mi=0;
    int t=n-(m-1);
    ma=t*(t-1)/2;
    t=n/m;
    int tt=n%m;
    mi=t*(t-1)/2*(m-tt);
    mi+=t*(t+1)/2*tt;
    cout<<mi<<' '<<ma<<endl;
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_44178736/article/details/114165596