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. WPF基础——继承

    1)  可以定义继承自其他类的类,关系是“父类/子类”.子类继承父类的成员(不严谨) 2)  定义语法“class子类:父类”,不指定父类则父类为Object,.Net中所有类都直接或者间接继承自Ob ...

  2. GridView边线Border设置

    1.黑色实线:(行列都有) <asp:GridViewID="GridView1"runat="server"CellPadding="3&qu ...

  3. Convert Binary Search Tree (BST) to Sorted Doubly-Linked List

    (http://leetcode.com/2010/11/convert-binary-search-tree-bst-to.html) Convert a BST to a sorted circu ...

  4. struts1标签(html:text)

    这个标签可能是出现频率最高的标签了. 功能: <html:text/>产生HTML语句: <input type=”text”…> 也就是在页面上产生input类型的显示标签. ...

  5. iScroll 4,把禁掉的:active样式还给我~

    iScroll这个移动端的滚动神器大家都非常熟悉了,直到现在仍是实现移动端Web滚动的首选方案之一... 当我接触移动端Web时iScroll已经有两个版本了,iScroll 4和iScroll 5, ...

  6. AutoCompleteTextView 自动提示

    在输入框中输入我们想要输入的信息就会出现其他与其相关的提示信息,这种效果在Android中是用AutoCompleteTextView实现的. public class MainActivity ex ...

  7. 使用Integer类实现二叉树排序

    class BinaryTree {     class Node {         private Comparable data;         private Node left;      ...

  8. (转)C++笔记:面向对象编程基础

    非常棒的总结 http://blog.csdn.net/liufei_learning/article/details/21312701 面向对象编程基础 面向对象编程基于三个基本概念: 数据抽象-类 ...

  9. 批处理[Batch]

    批处理 1. 定义:就是一堆DOS命令按一定顺序排列而形成的集合. 英文译为BATCH,批处理文件后缀BAT就取的前三个字母. 示例1:a.bat @echo off Netstat –a –n &g ...

  10. iphone 4 safrai fixed

    <script type="text/javascript"> if(navigator.userAgent.indexOf("Safari")&g ...