zoukankan      html  css  js  c++  java
  • 组合——Program B

        CodeForces 478B

    Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

     

    Description

      n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.

      Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

     

    Input

    The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants

    and the number of teams respectively.

     

    Output

    The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the

    maximum possible number of pairs of friends respectively.

     

    Sample Input

     
    Input
      5  1
    Output
     10  10
    Input
    3 2
    Output
    1 1
    Input
    6 3
    Output
    3 6




    题目大意:将n个人分到m个队中,求队中成为朋友个数的最大值与最小值。

    分析:此题是一个组合问题.










    代码如下:

    #include <iostream>
    #include<cstdio>

    
    
    
    
    

    using namespace std;
    long long n, m;
    long long cal(long long a)
    {
      return a*(a-1)/2;
    }
    int main()
    {
      while(scanf("%lld %lld",&n,&m)==2)
      {
        long long a=n/m;
        printf("%lld %lld ", cal(a)*(m-n%m) + cal(a+1)*(n%m), cal(n-m+1));
      }
    return 0;
    }

     
  • 相关阅读:
    vue表单验证定位到错误的地方
    INSPINIA Version 2.5 Bootstrap3
    volatile 彻底搞懂
    solr6.4.2之webservice兼容升级
    快速排序
    Elasticsearch调优篇 10
    TCP 连接为什么需要 3 次握手和 4 次挥手
    搜索技术与方案的选型与思考
    Elasticsearch调优篇 09
    Elasticsearch调优篇 08
  • 原文地址:https://www.cnblogs.com/xl1164191281/p/4749093.html
Copyright © 2011-2022 走看看