下面为求取组合数的代码:

 #include <stdio.h>
#define MAX 10009
int prime[];
void print(int *v, int length)
{
int i = ;
for (; i < length; i++)
printf("%d ", v[i]);
putchar('\n');
} int getPrime()
{
int i = , k = ;
int j = ;
int flag;
prime[] = ;
for (; i < ; i++) {
for (flag = , j = ; j < k; j++) {
if (i % prime[j] == ) {
flag = ;
break;
}
}
if (!flag)
prime[k++] = i;
}
print(prime, );
} int comb(int m, int n)
{
int count[] = { };
int i = , j = ;
int mm;
int mul = , tmp;
for (i = m; i > m - n; i--) {
mm = i;
for (j = ; mm != ; j++) {
if (mm % prime[j] == ) {
mm /= prime[j];
++count[j];
--j;
}
}
}
for (i = n; i >= ; i--) {
mm = i;
for (j = ; mm != ; j++)
if (mm % prime[j] == ) {
mm /= prime[j];
--count[j];
--j;
}
}
for (i = ; i < ; i++) {
tmp = count[i];
while (tmp) {
mul = (mul * prime[i]) % MAX;
tmp--;
}
}
return mul;
} int main()
{
getPrime();
printf("%d\n", comb(, ));
return ;
}

求组合数m_n的更多相关文章

  1. lucas求组合数C(n,k)%p

    Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...

  2. URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理

    URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...

  3. N!分解质因子p的个数_快速求组合数C(n,m)

    int f(int n,int p) { ) ; return f(n/p,p) + n/p; } https://www.xuebuyuan.com/2867209.html 求组合数C(n,m)( ...

  4. 求组合数、求逆元、求阶乘 O(n)

    在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...

  5. HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解

    题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...

  6. hdu 2519 求组合数

    求组合数 如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1) Sample Input5 //T3 2 //C3 25 34 43 68 0 Sample Outpu ...

  7. 求组合数 C++程序

    一 递归求组合数 设函数为void    comb(int m,int k)为找出从自然数1.2.... .m中任取k个数的所有组合. 分析:当组合的第一个数字选定时,其后的数字是从余下的m-1个数中 ...

  8. HDU 5698——瞬间移动——————【逆元求组合数】

    瞬间移动 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submis ...

  9. Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】

    任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...

随机推荐

  1. 15 Spring Data JPA概述

    Spring Data JPA 概述 Spring Data JPA 是 Spring 基于 ORM 框架.JPA 规范的基础上封装的一套JPA应用框架,可使开发者用极简的代码即可实现对数据库的访问和 ...

  2. 2020 webstorm 最新激活方式 有效期2021年11月 可用

    MIIElT25XE-eyJsaWNlbnNlSWQiOiJPUVQzT0oyNVhFIiwibGljZW5zZWVOYW1lIjoi5rC45LmF5r+A5rS7IGlkZWEubWVkZW1pb ...

  3. 【原创】(求锤得锤的故事)Redis锁从面试连环炮聊到神仙打架。

    这是why技术的第38篇原创文章 又到了一周一次的分享时间啦,老规矩,还是先荒腔走板的聊聊生活. 有上面的图是读大学的时候,一次自行车骑行途中队友抓拍的我的照片.拍照的地方,名字叫做牛背山,一个名字很 ...

  4. jupyternotebook安装

    本篇阅读目录 一.Jupyter notebook环境安装 二.爬虫介绍 回到顶部 一.Jupyter notebook环境安装 1.Anaconda 以及 安装步骤 Anaconda指的是一个开源的 ...

  5. 解决git推不上去1

    在使用 Android Studio 对源代码进行push到码云时可出错,报错如下: error: failed to push some refs to 'https://gitee.com/文件路 ...

  6. ML-Agents(二)创建一个学习环境

    ML-Agents(二)创建一个学习环境 一.前言 上一节我们讲了如何配置ML-Agents环境,这一节我们创建一个示例,主要利用Reinforcement Learning(强化学习). 如上图,本 ...

  7. vue依赖注入

    大家可能知道常规组件传值,父传子使用子组件定义好的props值,子传父可以使用子组件里面定义的时间this.$emit(); 然后很多层的情况,一层一层慢慢传太慢,vue提供了依赖注入的钩子:prov ...

  8. linux svn切换用户

    1. 临时切换 在所有命令下强制加上--username 和--password选项. 例如:svn up --username zhangsan --password 123456 2.永久切换 删 ...

  9. Spring Cloud - Nacos注册中心入门单机模式及集群模式

    近几年微服务很火,Spring Cloud提供了为服务领域的一整套解决方案.其中Spring Cloud Alibaba是我们SpringCloud的一个子项目,是提供微服务开发的一站式解决方案. 包 ...

  10. tensorflow一些API的基本理解

    1.tf.Session self._session = None opts = tf_session.TF_NewSessionOptions(target=self._target, config ...