Highly divisible triangular number

我的那个暴力求解,太耗时间了。

用了网上产的什么因式分解,质因数之类的。确实快!还是数学基础不行,只能知道大约。

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?

from math import sqrt
import time
def natSum(n):
    x = 1
    count = 0
    sum = 0
    while count <= n:
        sum += x
        count = 0
        for i in range(1,int(sqrt(sum))+1):
            if sum % i == 0:
                count += 2
        if sqrt(sum)==int(sqrt(sum)):
                count -= 1
        print x,sum,count,n

        x += 1

natSum(500)
'''
start=time.time()
now=2
num=1
t = 0
while t <= 500 :
    num=num+now
    now+=1
    t=0
    for x in range(1,int(sqrt(num))+1):
        if num%x==0:
            t+=2
    if sqrt(num)==int(sqrt(num)):
        t=t-1

    print num
print num
print time.time()-start
'''
        

时间: 2024-09-19 09:43:46

Highly divisible triangular number的相关文章

Highly divisible triangular number( Problem 12)

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 fir

Triangular Sums

Triangular Sums 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + - + n, is the sum of the first n integers. It is the number of points in a triangular array with n points on side. For example T(4): X X X X X X X X X X Writ

《数学与泛型编程:高效编程的奥秘》一3.1 整数的几何属性

3.1 整数的几何属性 毕达哥拉斯(Pythagoras)这个名字,大多数人都是从同名的定理中听说的.这位古希腊的数学家和哲学家曾经提出一个理念:要想理解世界,就必须先懂得数学.他还发现了数字的很多奇妙性质,而且认为这些发现无论有没有实际的用途,其本身都具备巨大的价值.亚里士多德的学生亚里士多塞诺斯(Aristoxenus)曾经说道:"他极其重视算术研究工作,并把这些研究从实用的商业领域中划分出来,单独加以推进." 毕达哥拉斯(Pythagoras,约公元前570-公元前490) 毕达

UVa 10624:Super Number, Rujia Liu的神题

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=112&page=show_problem&problem=1565 原题: Don't you think 162456723 very special? Look at the picture below if you are unable to find its speciality. (a | b mea

UVa 11371 Number Theory for Newbies (water ver.)

11371 - Number Theory for Newbies Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2366 Given any positive integer, if we permute its digits, the differenc

【原创】RabbitMQ官网文档翻译 -- Highly Available Queues

      为了方便工作中使用,对 RabbitMQ 的[高可用]相关文档进行了翻译,鉴于自己水平有限,翻译中难免有纰漏产生,如果疑问,欢迎指出探讨.此文以中英对照方式呈现. 官方原文:http://www.rabbitmq.com/ha.html ============== 我是分割线 =============== Highly Available Queues高可用 queue If your RabbitMQ broker consists of a single node, then

Dynamo: Amazon’s Highly Available Key-value Store

www.allthingsdistributed.com/2007/10/amazons_dynamo.html , 英文版 http://blog.163.com/woshitony111@126/blog/static/71379539201231492557944/ , 中文版   1 Overview Amazon服务平台中的许多服务只需要主键访问数据存储. 对于许多服务, 如提供最畅销书排行榜, 购物车, 客户的偏好, 会话管理, 销售等级, 产品目录, 常见的使用关系数据库的模式会导

the smallest positive number

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?   程序比较好编,就是考验计算机.最大范围也是预估的,边写边调. 尽管算对了,但方式可能不

Megastore - Providing Scalable, Highly Available Storage for Interactive Services

1. INTRODUCTION Interactive online services are forcing the storage community to meet new demands as desktop applications migrate to the cloud. Services like email, collaborative documents, and social networking have been growing exponentially and ar