(Problem 53)Combinatoric selections
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的更多相关文章
- (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, ...
- (Problem 22)Names scores
Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-tho ...
- (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 ...
- (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 ...
- (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 ...
- (Problem 70)Totient permutation
Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number ...
- (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 ...
- (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 ...
- (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 ...
随机推荐
- SICP 练习 (2.9)解决摘要:宽度和区间运算的关系间隔
SICP 2.9 像是一个数学题,要我们证明区间的和与差的宽度是被加和被减的区间的宽度的函数,而对于乘法和除法来说不成立. 书中所谓宽度就是区间起点和终点差的一半.以我看来更像是区间宽度的一半.无论怎 ...
- 从零开始学习UNITY3D(GUI篇 2)
复合控件极其使用,toolbar,selectgrid 先看效果图: toolbar可以看作是一个button按钮的集合,一次只能点击一个按钮, selectgrid又可以堪称是一个toolbar的集 ...
- new、delete与malloc、free的详解
内容清单: 1. C语言中的函数malloc和free 2. C++中的运算符new和delete 3. new/delete与malloc/free之间的联系和区别 4. C/C++程序的内 ...
- Asp.net 获取图片列表并打包下载
先引用:ICSharpCode.SharpZipLib.dll 后台代码: using System.IO; using ICSharpCode.SharpZipLib.Zip; using ICSh ...
- 在centos6.5下yum仓库的创建
第一步:打开虚拟机,装入光盘镜像,选择为已连接 第二步: df -h mount umount /dev/sr0 mkdir /centos mount /dev/sr0 /centos mkdir ...
- Excel表格中汉字转拼音
一.使用“实用汉字转拼音V4.8” 软件 下载地址http://www.orsoon.com/soft/4413.html 或则百度 很多的 二.Excel自定义函数方法: 1.启动Excel 200 ...
- Windows 10 : 使用BCDboot恢复双系统启动
电脑装上win10以后,立马把原来系统的启动信息删了.结果有个软件需要反激活,但是Win10已经没有Boot.ini这样的启动配置文件. 花了好多时间查找,发现这篇文章.实际操作倒是很简单.执行以下命 ...
- hive 学习笔记精简
创建表: drop table t create table if not exists t (t string) partitioned by (log_date string) row forma ...
- 使用分析函数实现Oracle 10G提供的CONNECT_BY_ISLEAF和CONNECT_BY_ROOT的功能(转载)
文章转载至:http://blog.csdn.net/wzy0623/article/details/1644049 如果,有侵犯您权益的地方,烦请及时的告知我,我会即刻停止侵权行为 Oracle 1 ...
- Twemproxy 分布式集群缓存代理服务器
Twemproxy 分布式集群缓存代理服务器 是一个使用C语言编写.以代理的方式实现的.轻量级的Redis代理服务器, 它通过引入一个代理层,将应用程序后端的多台Redis实例进行统一管理, 使 应用 ...