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
projecteuler---->problem=12----Highly divisible triangular number的更多相关文章
- project euler 12 Highly divisible triangular number
Highly divisible triangular number Problem 12 The sequence of triangle numbers is generated by addin ...
- Highly divisible triangular number
我的那个暴力求解,太耗时间了. 用了网上产的什么因式分解,质因数之类的.确实快!还是数学基础不行,只能知道大约. The sequence of triangle numbers is generat ...
- Project Euler Problem 12-Highly divisible triangular number
最直接的想法就是暴力搞搞,直接枚举,暴力分解因子.再好一点,就打个素数表来分解因子.假设num=p1^a1p2^a2...pn^an,则所有因子个数为(a1+1)(a2+1)...(an+1). 再好 ...
- [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 ...
- uoj problem 12 猜数
题目大意 每次询问给出g,l,有\(a*b = g*l = n\),且\(a,b\)均为\(g\)的倍数.求\(a+b\)的最小值和\(a-b\)的最大值. 题解 因为\(a,b\)均为\(g\)的倍 ...
- Python练习题 040:Project Euler 012:有超过500个因子的三角形数
本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...
- PE刷题记
PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...
- Problem 28
Problem 28 https://projecteuler.net/problem=28 Starting with the number 1 and moving to the right in ...
- Python练习题 045:Project Euler 017:数字英文表达的字符数累加
本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter coun ...
随机推荐
- action类中属性驱动和模型驱动的区别
1.Struts2的属性驱动 在Action类中,属性××通过get××()和set××()方法,把参数在整个生命周期内进行传递,这就是属性驱动 代码如下: package org.abu.csdn. ...
- ubuntu 安装 navicat
下载navicat解压到opt目录 创建桌面快捷方式sudo vim /usr/share/applications/navicat.desktop [Desktop Entry] Encoding= ...
- PHP:现有图片验证码类
文章来源:http://www.cnblogs.com/hello-tl/p/7593022.html <?php class TL_Captcha_img{ private $image; / ...
- LINUX系统---中级相关操作和知识
LINUX系统的中级,来搞一些LINUX安全相关的东西,还有在公司生成中长搞的集群. RHCS集群 什么是高可用 什么是热备 什么是分布式
- MySQL-----一对一
一对一: 用户表和博客表 用户表(userinfo): 用户id 用户名 1 George 2 root 3 Bruce 4 Catherine 博客表: 博客id 博客名 用户id(FK + 唯一) ...
- Python Pandas库的学习(二)
今天我们继续讲下Python中一款数据分析很好的库.Pandas的学习 接着上回讲到的,如果有人听不懂,麻烦去翻阅一下我前面讲到的Pandas学习(一) 如果我们在数据中,想去3,4,5这几行数据,那 ...
- Python中的数据类型之字符串
字符串的定义,可是使用类似下面的方式 name = "hello python" Python 中字符串自带了一些常用的方法,比如: title() #用来将每个单词首字母大写up ...
- 分享大牛开发经验,浅谈java程序员职业规划
在中国有很多人都认为IT行为是吃青春饭的,如果过了30岁就很难有机会再发展下去!其实现实并不是这样子的,在下从事.NET及JAVA方面的开发的也有8年的时间了,在这...... 在中国有很多人都认为I ...
- SSM java.lang.NullPointerException
如上图所示的异常 原来是少了这个东西,加上就好了
- 在win10配置环境变量
从win7升级成win10后找不到在哪配置环境变量...手动再见ヾ( ̄▽ ̄)Bye~,废话不多说,下面开始图文模式: 1)打开文件资源管理器,点左上角的"计算机"