There are exactly ten ways of selecting three from five, 12345:

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

In combinatorics, we use the notation, 5C3 = 10.

In general,

It is not until n = 23, that a value exceeds one-million: 23C10 = 1144066.

How many, not necessarily distinct, values of  nCr, for 1  n  100, are greater than one-million?

题目大意:

从五个数12345中选出三个数一共有十种方法:

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

在组合数学中我们用5C3 = 10来表示.

n = 23时产生第一个超过一百万的数: 23C10 = 1144066.

对于nCr,  1  n  100,有多少超过100万的值?包括重复的在内。

//(Problem 53)Combinatoric selections
// Completed on Fri, 14 Feb 2014, 07:20
// Language: C11
//
// 版权所有(C)acutus (mail: acutus@126.com)
// 博客地址:http://www.cnblogs.com/acutus/
#include<stdio.h>
#include<math.h> long long combinatoric(int n, int r) //计算组合数的函数
{
int i;
long long s = ;
if(r > n / ) r = n - r;
for(i = n; i >= n - r + ; i--) {
s *= i;
}
for(i = ; i <= r; i++) {
s /= i;
}
return s;
} int main()
{
int i, j, s;
s = ;
for(i = ; i <= ; i++) {
j = ;
while(combinatoric(i, j) < ) j++;
if(i % ) {
s += (i / - j + ) * ; //利用组合数的对称性,分奇偶两种情况
} else {
s += (i / - j) * + ;
}
}
printf("%d\n", s);
return ;
}
Answer:
4075

(Problem 53)Combinatoric selections的更多相关文章

  1. (Problem 29)Distinct powers

    Consider all integer combinations ofabfor 2a5 and 2b5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, ...

  2. (Problem 22)Names scores

    Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...

  3. (Problem 73)Counting fractions in a range

    Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...

  4. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  5. (Problem 41)Pandigital prime

    We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly o ...

  6. (Problem 70)Totient permutation

    Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...

  7. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  8. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  9. (Problem 72)Counting fractions

    Consider the fraction, n/d, where n and d are positive integers. If nd and HCF(n,d)=1, it is called ...

随机推荐

  1. 填充Z形二维数组

    形如  1   3 4 10  2  5 9 11  6  8 12 15  7 13 14 16 的数组称谓Z形二维数组.填充这样的数组其实只要按照Z形进行行走填充即可,设置一个flag指示方向,行 ...

  2. SICP 习题 (1.10)解题总结

    SICP 习题 1.10 讲的是一个叫“Akermann函数”的东西,去百度查可以查到对应的中文翻译,叫“阿克曼函数”. 就像前面的解题总结中提到的,我是一个数学恐惧者,看着稍微复杂一点的什么函数我就 ...

  3. NGINX 多个域名配置

    多个域名配置: 依赖于 include  这个功能会加在 这2个文件夹下的所有配置文件. 所以我们可以配置多个   conf  放置于这些文件夹中.这样就是先了多个域名配置 conf 内容大致如下 s ...

  4. JavaScript引用类型之Array数组之强大的splice()方法

    splice()方法可以说是Array数组最强大的方法,他的用法很多,主要用法是向数组的中部插入项! 下面是它的用法: arrayObject.splice(index,howmany,element ...

  5. <转>机器学习笔记之奇异值分解的几何解释与简单应用

    看到的一篇比较好的关于SVD几何解释与简单应用的文章,其实是有中文译本的,但是翻译的太烂,还不如直接看英文原文的.课本上学的往往是知其然不知其所以然,希望这篇文能为所有初学svd的童鞋提供些直观的认识 ...

  6. 软件开发常用Linux命令

    解压缩 tar -zxvf xxx.tar.gz 文件显示及查找常用于分析log //显示file中包含aaa的行 cat <file>|grep aaa 查看cpu memory基本信息 ...

  7. NSURLSessionConfiguration的简单实用

    NSURLSessionConfiguration 基于前面学习了NSURLSession的知识,这边文章就讲下NSURLSessionConfiguration相关应用,(这名字可真长). 简而言之 ...

  8. day3_python学习笔记_chapter5_数字

    1. 整形的表示范围-2^32~2^32 - 1 : 长整形表示:aLong = 99999L 2. 复数的属性, num.real,该复数的实部, num.imag,该复数的虚部.num.conju ...

  9. hdu 4454 Stealing a Cake (三分)

    Stealing a Cake Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  10. Java的函数与函数重载

    关于Java的函数与函数重载 关于Java的函数与函数重载 1. 函数 假设有一个游戏程序,程序在运行过程中,要不断地发射炮弹.发射炮弹的动作都需要使用一段百行左右的程序代码,在每次发射炮弹的地方都要 ...