题目链接:http://codeforces.com/gym/101775/problem/A

It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: since every 3 or more persons could make a chat group, there can be 42 different chat groups.

Given N persons in a dormitory, and every K or more persons could make a chat group, how many different chat groups could there be?

Input
The input starts with one line containing exactly one integer T which is the number of test cases.

Each test case contains one line with two integers N and K indicating the number of persons in a dormitory and the minimum number of persons that could make a chat group.

1 ≤ T ≤ 100.
1 ≤ N ≤ 10^9.
3 ≤ K ≤ 10^5.

Output
For each test case, output one line containing "Case #x: y" where x is the test case number (starting from 1) and y is the number of different chat groups modulo 1000000007.

Example
Input
1
6 3
Output
Case #1: 42

题意:

听说一个寝室六个人有七个群?但实际上如果六人寝里三个人及以上组成不同的群的话,可以组成 $42$ 个群……

现在给出一个 $n$ 人寝室,要求计算 $k$ 人及以上的不同的群可以建几个?

题解:

$C_{n}^{k}+ \cdots + C_{n}^{n} = (C_{n}^{0}+ C_{n}^{1} + \cdots + C_{n}^{n}) - (C_{n}^{0}+ C_{n}^{1} + \cdots + C_{n}^{k-1})$

又根据二项式展开可知 $2^n = (1+1)^{n} = C_{n}^{0} \times 1^{0} \times 1^{n} + C_{n}^{1} \times 1^{1} \times 1^{n-1} + \cdots + C_{n}^{n} \times 1^{n} \times 1^{0} = C_{n}^{0} + C_{n}^{1} + \cdots + C_{n}^{n}$

因此答案即为 $2^{n} - (C_{n}^{0}+ C_{n}^{1} + \cdots + C_{n}^{k-1})$。

运用累乘的方式计算 $C_{n}^{0}, C_{n}^{1}, \cdots, C_{n}^{k-1}$,注意除法要使用逆元。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=;
ll n,k; ll fpow(ll a,ll b)
{
ll r=,base=a%MOD;
while(b)
{
if(b&) r*=base,r%=MOD;
base*=base;
base%=MOD;
b>>=;
}
return r;
}
ll inv(ll a){return fpow(a,MOD-);} int main()
{
int T;
cin>>T;
for(int kase=;kase<=T;kase++)
{
scanf("%lld%lld",&n,&k);
if(n<k)
{
printf("Case #%d: 0\n",kase);
continue;
}
ll sum=+n,tmp=n;
for(ll i=;i<=k-;i++)
{
tmp=(((tmp*(n-i))%MOD)*inv(i+))%MOD;
sum=(sum+tmp)%MOD;
}
ll ans=(fpow(,n)-sum+MOD)%MOD;
printf("Case #%d: %d\n",kase,ans);
}
}

Gym 101775A - Chat Group - [简单数学题][2017 EC-Final Problem A]的更多相关文章

  1. Gym - 101775A Chat Group 组合数+逆元+快速幂

    It is said that a dormitory with 6 persons has 7 chat groups ^_^. But the number can be even larger: ...

  2. HDU 6467 简单数学题 【递推公式 && O(1)优化乘法】(广东工业大学第十四届程序设计竞赛)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6467 简单数学题 Time Limit: 4000/2000 MS (Java/Others)    M ...

  3. HDU 6467.简单数学题-数学题 (“字节跳动-文远知行杯”广东工业大学第十四届程序设计竞赛)

    简单数学题 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  4. Discrete Function(简单数学题)

    Discrete Function There is a discrete function. It is specified for integer arguments from 1 to N (2 ...

  5. JZOJ 5773. 【NOIP2008模拟】简单数学题

    5773. [NOIP2008模拟]简单数学题 (File IO): input:math.in output:math.out Time Limits: 1000 ms  Memory Limits ...

  6. Chat Group gym101775A(逆元,组合数)

    传送门:Chat Group(gym101775A) 题意:一个宿舍中又n个人,最少k(k >= 3)个人就可以建一个讨论组,问最多可以建多少个不同的讨论组. 思路:求组合数的和,因为涉及除法取 ...

  7. [JZOJ5773]【NOIP2008模拟】简单数学题

    Description       话说, 小X是个数学大佬,他喜欢做数学题.有一天,小X想考一考小Y.他问了小Y一道数学题.题目如下:      对于一个正整数N,存在一个正整数T(0<T&l ...

  8. Gym 102056I - Misunderstood … Missing - [DP][The 2018 ICPC Asia-East Continent Final Problem I]

    题目链接:https://codeforces.com/gym/102056/problem/I Warm sunshine, cool wind and a fine day, while the ...

  9. 组合数+逆元 A - Chat Group Gym - 101775A

    题目链接:https://cn.vjudge.net/contest/274151#problem/A 具体思路:我们可以先把所有的情况算出来,为2^n.然后不合法的情况减去就可以了.注意除法的时候要 ...

随机推荐

  1. M600 Pro 安装问题解决

    1.遥控器版本为1.2.10 提示版本已是最新版本,那么Lightbridge2 必须是1.1.60 不能是1.1.70 2.卸载机翼的时候,尽量用飞机带的那把工具 3.机翼安装 135 逆时针 cc ...

  2. window炫丽cmd的别名cmder

    windows下的cmd,色彩度用起来不爽,cmder是对cmd的补充,界面很清爽 01.下载 https://github.com/cmderdev/cmder http://cmder.net/ ...

  3. LIBTUX_CAT:466: ERROR: tpopen TPERMERR xa_open returned XAER_INVAL

    tmboot 启动Tuxedo服务失败,从ULOG日志中看到以下错误: 100534.MATHXH!TMS_ORA10G.22600.4076.0: LIBTUX_CAT:466: ERROR: tp ...

  4. 关于Discuz! X系列UC_Server 本地文件包含漏洞

    最近又发现discuz论坛被挂马了,决定好好研究一下discuz的漏洞,技术债始终要还是要还的 一.问题发现 快要睡觉的时候,突然收到一封邮件,发现服务器上的文件被篡改了,立即登录服务器,清空恶意文件 ...

  5. asp.net中WebResponse 跨域访问示例

    前两天,一个朋友让我帮他写这样一个程序:在asp.net里面访问asp的页面,把数据提交对方的数据库后,根据返回的值(返回值为:OK或ERROR),如果为OK再把填入本地数据库.当时,想当然,觉得很简 ...

  6. sqoop导入数据到hive中元数据问题

    简单配置了sqoop之后开始使用,之前用的时候很好用,也不记得有没有启动hivemetastore,今天用的时候没有启动,结果导入数据时,如果使用了db.tablename,就会出现找不到数据库的错, ...

  7. Oracle中查看所有表和字段

    获取表字段: select * from user_tab_columns where Table_Name='用户表' order by column_name 获取表注释: select * fr ...

  8. 循环神经网络(Recurrent Neural Networks, RNN)介绍

    目录 1 什么是RNNs 2 RNNs能干什么 2.1 语言模型与文本生成Language Modeling and Generating Text 2.2 机器翻译Machine Translati ...

  9. 基于【CentOS-7+ Ambari 2.7.0 + HDP 3.0】搭建HAWQ数据仓库——操作系统配置,安装必备软件

    注意未经说明,所有本文中所有操作都默认需要作为root用户进行操作. 一.安装zmodem,用于远程上传下载文件,安装gedit,方便重定向到远程windows上编辑文件(通过xlanuch) [ro ...

  10. CocoaPods 添加WebP失败解决办法

    pod 'sdwebimage/webp' 下载libwebp 超时 [!] Error installing libwebp [!] /usr/bin/git clone https://chrom ...