Chinaunix首页 | 论坛 | 博客
  • 博客访问: 86602
  • 博文数量: 47
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 625
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-11 12:11
文章分类

全部博文(47)

文章存档

2008年(47)

我的朋友

分类:

2008-11-23 13:10:13

Problem 53

26 September 2003

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,

nCr =
n!

r!(nr)!
,where r n, n! = n(n1)...321, and 0! = 1.

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?

找到第一个r使得nCr > 1000000, 则对于n其大于1000000的数量为i - 2*j + 1

def fun53():
    f = [1]*101
    for i in range(2, 101):
        f[i] = i*f[i-1]
    #print f
    count = 0
    for i in range(23, 101):
        for j in range(0, i/2+1):
            t = f[i]/(f[j]*f[i-j])
            if t > 1000000:
                #print i, j
                count += i - 2*j + 1
                """
                if i%2 == 0:
                    count += ((i+1)/2 - j)*2
                else:
                    count += (i/2 -j)*2 + 1
                """
                break
    return count

answer 4075
time:0.0
阅读(406) | 评论(0) | 转发(0) |
0

上一篇:Problem 52

下一篇:Problem 56

给主人留下些什么吧!~~