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. python 调用exe程序

    #!/usr/bin/python #-*- coding:utf-8 -*- import os, subprocess import tkMessageBox import msg_box def ...

  2. vue 轮播插件使用

    <template> <div> <Swiper ref="swiper" v-if="list.length > 0" : ...

  3. <Spring Cloud>入门一 Eureka Server

    1.搭建父工程 主要是添加版本依赖,此处版本是: spring-boot  : 2.0.8.RELEASE spring-cloud : Finchley.SR2 <?xml version=& ...

  4. Python:用户自定义异常

    实际开发中,有时候系统提供的异常类型不能满足开发的需求.这时候你可以通过创建一个新的异常类来拥有自己的异常.异常类继承自 Exception 类,可以直接继承,或者间接继承. 1.自定义异常类型 #1 ...

  5. Python之粘包

    Python之粘包 让我们基于tcp先制作一个远程执行命令的程序(1:执行错误命令 2:执行ls 3:执行ifconfig) 注意注意注意: res=subprocess.Popen(cmd.deco ...

  6. Java Class 利用classpath来获取源文件地址

    利用classpath来获取源文件地址 @author ixenos 应用场景 Properties props = new Properties(); /** * . 代表java命令运行的目录 * ...

  7. [OJ#40]后宫佳丽

    [OJ#40]后宫佳丽 试题描述 如果机房要关门了,或者有妹子在等你,你可以直接看最后一句话. Fyq 是一只饥渴的鸭子. Fyq 有一个充实的后宫,可惜他总是体力不支,为此他经常苦恼,总是想方设法让 ...

  8. hosts.allow和hosts.deny文件

    之前想通过外部主机访问自己主机上的VMWare虚拟机,使用了VMWare的NAT端口映射,经过一番尝试,算是成功了,总结一下. VMWare NAT端口映射就可以将虚拟机上的服务映射成自己主机上的端口 ...

  9. android中webview的实现

    设置从当前页面打开链接,而不是跳转到系统默认浏览器打开: webview.setWebViewClient(new WebViewClient(){ @Override public boolean ...

  10. Aizu - 0558 Cheese (bfs)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=49879 在H * W的地图上有N个奶酪工厂,分别生产硬度为1-N的奶酪.有一 ...