zoukankan      html  css  js  c++  java
  • projecteuler---->problem=12----Highly divisible triangular number

    title:

    The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

    1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

    Let us list the factors of the first seven triangle numbers:

     1: 1
     3: 1,3
     6: 1,2,3,6
    10: 1,2,5,10
    15: 1,3,5,15
    21: 1,3,7,21
    28: 1,2,4,7,14,28

    We can see that 28 is the first triangle number to have over five divisors.

    What is the value of the first triangle number to have over five hundred divisors?

    翻译:

    「三角数」即用递增的自然数相加得到的数。因此第7个三角数为1 + 2 + 3 + 4 + 5 + 6 + 7 = 28。

    前10个三角数为:

    1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

    先让我们来看看前7个三角数各自都有哪些因数吧:

    • 1: 1
    • 3: 1,3
    • 6: 1,2,3,6
    • 10: 1,2,5,10
    • 15: 1,3,5,15
    • 21: 1,3,7,21
    • 28: 1,2,4,7,14,28

    可见。28是第一个拥有超过5个因数的三角数。

    那么第一个拥有超过500个因数的三角数是……?

    解答:

    import time
    def getCount(a):
    	count=0
    	b=a
    	if a==1:
    		return 1
    	if a%2==0:
    		i=2
    	else :
    		i=3
    	while i < b:
    		if a%i==0:
    			count+=2
    			b=a/i	
    			if b==i:
    				count-=1
    				break		
    		i+=1
    	return count+2
    s=0
    i=1
    start=time.time()
    while True:
    	s += i
    	size=getCount(s)
    	if size >= 500:
    		break
    	i+=1;
    stop=time.time()
    print "time is ",stop-start
    print s	
    	
    	


  • 相关阅读:
    poj 1753 -- Flip Game
    hdu 2209 -- 翻纸牌游戏
    文件系统的挂载与卸载挂载
    我的vim配置(一)
    Poj 3687 -- Labeling Balls
    主动激发“onclick”事件;prompt
    this
    函数嵌套
    调用函数时传递的实参个数arguments.length; ,函数定义时的形参个数sum.length
    回调函数,用户定义的排序规则
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7220408.html
Copyright © 2011-2022 走看看