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

 #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. git涨姿势(一)

    今天遇到了一个git冲突问题,解决冲突方案我是当然知道的,就是本地不知道何时自己傻不拉几的新建了一个relese分支,而remote是没有release分支的,需要拉取的是release/V1.4.2 ...

  2. 02 JPA

    JPA概述 JPA的全称是Java Persistence API, 即Java 持久化API,是SUN公司推出的一套基于ORM的规范,内部是由一系列的接口和抽象类构成.       JPA通过JDK ...

  3. 单列集合List

    1.Vector和ArrayList以及LinkedList区别和联系.应用场景 线程安全: Vector:如果创建Vector时没有指定容量,则默认容量为10,底层基于数组实现,线程是安全的,底层采 ...

  4. 将root用户权限赋予普通用户

    将root用户权限赋予普通用户 普通用户想要拥有root用户的权限,必须修改/etc/sudoers文件 ,还必须使用visudo命令修改.一是因为这个命令能防止多个用户同时修改这个文件,二是能进行有 ...

  5. C++ 指针实现字符串倒序排列

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <coni ...

  6. go源码分析(一) 通过调试看go程序初始化过程

    参考资料:Go 1.5 源码剖析 (书签版).pdf 编写go语言test.go package main import ( "fmt" ) func main(){ fmt.Pr ...

  7. Pending 打断点

    pending 英['pendɪŋ],美['pɛndɪŋ] a. 未决定的, 待决的, 行将发生的, 向外伸出的prep. 在等待...之际, 直到...时为止, 在...期间, 在...过程中 pe ...

  8. Java第一节课动手动脑

    在第一节课的动手动脑中,主要解决四则运算问题. 首先第一个是出30道四则运算题目,在100以内.这个问题需要控制随机数生成的范围和结果的范围在100以内就可以. 第一次改进是3点:一为避免重复,二为定 ...

  9. Natas27 Writeup(mysql溢出截断漏洞)

    Natas27: 一个登录节界面,查看源码. <html> <head> <!-- This stuff in the header has nothing to do ...

  10. axios Api介绍

    1.Performing a GET request axios.get('/user?ID=12345') .then(function (response) { // handle success ...