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

projecteuler----&gt;problem=12----Highly divisible triangular number的更多相关文章

  1. project euler 12 Highly divisible triangular number

    Highly divisible triangular number Problem 12 The sequence of triangle numbers is generated by addin ...

  2. Highly divisible triangular number

    我的那个暴力求解,太耗时间了. 用了网上产的什么因式分解,质因数之类的.确实快!还是数学基础不行,只能知道大约. The sequence of triangle numbers is generat ...

  3. Project Euler Problem 12-Highly divisible triangular number

    最直接的想法就是暴力搞搞,直接枚举,暴力分解因子.再好一点,就打个素数表来分解因子.假设num=p1^a1p2^a2...pn^an,则所有因子个数为(a1+1)(a2+1)...(an+1). 再好 ...

  4. [LeetCode&Python] Problem 171. Excel Sheet Column Number

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  5. uoj problem 12 猜数

    题目大意 每次询问给出g,l,有\(a*b = g*l = n\),且\(a,b\)均为\(g\)的倍数.求\(a+b\)的最小值和\(a-b\)的最大值. 题解 因为\(a,b\)均为\(g\)的倍 ...

  6. Python练习题 040:Project Euler 012:有超过500个因子的三角形数

    本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...

  7. PE刷题记

    PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...

  8. Problem 28

    Problem 28 https://projecteuler.net/problem=28 Starting with the number 1 and moving to the right in ...

  9. Python练习题 045:Project Euler 017:数字英文表达的字符数累加

    本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...

随机推荐

  1. 01--安装Activiti流程设计器eclipse插件

    Activiti1 安装流程设计器eclipse插件 Name:Activiti BPMN 2.0 designer(随便起个名字) Location: http://activiti.org/des ...

  2. 使用HTML,CSS快速导出数据到Excel

    在应用中经常会遇到要从系统或数据库中导出数据平面文件,一般是导出到txt,csv或excel.txt和csv一般用在系统间的数据交换, 而excel一般有较好的显示效果,可以按照一定的模板导出,导出就 ...

  3. [POJ2774][codevs3160]Long Long Message

    [POJ2774][codevs3160]Long Long Message 试题描述 The little cat is majoring in physics in the capital of ...

  4. Redis事务【十二】

    一.概述: 和众多其它数据库一样,Redis作为NoSQL数据库也同样提供了事务机制.在Redis中,MULTI/EXEC/DISCARD/WATCH这四个命令是我们实现事务的基石.相信对有关系型数据 ...

  5. springboot-jjwt HS256加解密(PS:验证就是解密)

    最近项目需要用到类似access token进行加解密.验签的需求,本人在此做个小笔记记录一下,以供他人参考. 一共会用到2中加解密,HS256 和 RS256,本文只是对 HS256做个备注,好了直 ...

  6. Eclipse-Java代码规范和质量检查插件-阿里编码规约

    此工具配套阿里巴巴Java开发手册:http://www.cnblogs.com/EasonJim/p/6436387.html Eclipse安装和使用方法:https://github.com/a ...

  7. MongoDB小结23 - 索引简介

    MongoDB中的索引,可以看作是书的目录. 想象一下给你一本没有目录的书,然后让你去查询指定内容,我只想说,我不是电脑,我很蛋疼! 让你翻没有目录的书,就跟让电脑查询没有索引的集合一样,从头查询到尾 ...

  8. k-d树及八叉树

    http://en.wikipedia.org/wiki/K-d_tree http://en.wikipedia.org/wiki/Octree

  9. Setting up Storm and Running Your First Topology

    http://www.haroldnguyen.com/blog/2015/01/setting-up-storm-and-running-your-first-topology/ --------- ...

  10. ubuntu语言设置成汉语

    打开设置system setting,进入语言支持,有语言和地区格式.下载须要的语言并应用到整个系统. 按说明来就可以 这样的方法使得部分英语变为汉语.