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. Sublime Text 3:3114的安装(目前最新),插件emmet的安装

    随便一些好了. 直接英文版吧,建议不要找中文版,学习英语不是? https://www.sublimetext.com/3   下载 https://github.com/wbond/package_ ...

  2. Deep Learning(深度学习)学习笔记整理系列之(三)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  3. oracle归档日志

    前几天因为导入大的东西,弄得很久都没动静,一看最后才发现是归档满了.但是很多的命令还是很是很不熟悉,所以看了下,百度了下.整理下这个. 1.查看归档日志大小及使用情况 select * from v$ ...

  4. 线性插值(linear interpolation)

    线性插值通常用于:使用离散的样本来重建连续的信号.在计算机图形学中,这些样本可能是纹理.动画关键帧等. template <class T> T Lerp(T& a, T& ...

  5. realloc,c语言

    realloc #include <stdlib.h> main() { char* ptr=NULL; char* ptr2=NULL; ptr = malloc(); printf(& ...

  6. [C#技术参考]Socket传输结构数据

    最近在做一个机器人项目,要实时的接收机器人传回的坐标信息,并在客户端显示当前的地图和机器人的位置.当然坐标的回传是用的Socket,用的是C++的结构体表示的坐标信息.但是C#不能像C++那样很eas ...

  7. HDU2955-Robberies

    描述: The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usual ...

  8. tomcat无法正常启动的一个原因

    简要报错信息: java.lang.IllegalArgumentException: Document base E:\apache-tomcat-7.0.65\webapps\springmvc0 ...

  9. nodejs安装指定版本

    由于express有各种不同的版本,不同的版本开发方式有所不同,如果想安装指定版本可以选择全局安装指定版本: 安装步骤如下: (1) 安装2.5.8版本的express的方法: C:\Users\Li ...

  10. web编程速度大比拼(nodejs go python)(非专业对比)

    C10K问题的解决,涌现出一大批新框架,或者新语言,那么问题来了:到底谁最快呢?非专业程序猿来个非专业对比. 比较程序:输出Hello World! 测试程序:siege –c 100 –r 100 ...