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. NOIP专题复习2 图论-生成树

    目录 一.知识概述 二.典型例题 1.口袋的天空 三.算法分析 (一)Prim算法 (二)Kruskal 四.算法应用 1.[NOIP2013]货车运输 五.算法拓展 1977: [BeiJing20 ...

  2. JavaScript中的特殊数据类型

    JavaScript中的特殊数据类型 制作人:全心全意 转义字符 以反斜杠开头的不可显示的特殊字符通常为控制字符,也被称为转义字符.通常转义字符可以在字符串中添加不可显示的特殊字符,或者防止引号匹配混 ...

  3. c++基础_杨辉三角形

    #include <iostream> using namespace std; int main(){ int n; cin>>n; ][]; ;i<n;i++){ a ...

  4. PHP:分页类(比较庞大不建议在项目中用)

    文章来源:http://www.cnblogs.com/hello-tl/p/7685178.html <?php //地址 //page::$url=''; //每页的条数 默认10 //pa ...

  5. <c:foreach> 标签获取循环次数

    <c:forEach var="i" begin="1" end="9" varStatus="status"&g ...

  6. IDEA的Maven Projects无法显示

    记一个小坑: 前两天重装了一下电脑系统,下载了个最新的IDEA2018.3.5,把Maven.JDK.TomCat都设置好了 今天打开IDEA创建一个新的Maven项目,项目没有显示让我导入Maven ...

  7. 任务3.站会或DoD

    三选一 1.为开展敏捷团队:尝试一下引入站会 2.正在实践敏捷团队:定义DoD 3.从本次和上次学习中自己找出一个任务 <我们知道何时才算完成> <富有成效的每日站会> 目前所 ...

  8. Webdriver概述(selenium对应浏览器版本)

    Webdriver (Selenium2)是一种用于Web应用程序的自动测试工具,它提供了一套友好的API,与Selenium 1(Selenium-RC)相比,Webdriver 的API更容易理解 ...

  9. 九度oj 题目1058:反序输出

    题目1058:反序输出 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:9677 解决:3495 题目描述: 输入任意4个字符(如:abcd), 并按反序输出(如:dcba) 输入: 题目可 ...

  10. nyoj 96 n-1位数(处理前导 0 的情况)(string)

    n-1位数 时间限制:3000 ms  |            内存限制:65535 KB 难度:1   描述 已知w是一个大于10但不大于1000000的无符号整数,若w是n(n≥2)位的整数,则 ...