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 ...
随机推荐
- Java中数组在内存中的图解
Java中的数组在内存中的图解,其实对于数组,还是比较熟悉的,平时用的也是很多的,在看数据结构与算法的极客时间专栏,最常用的10个数据结构:数组.链表.栈.队列.散列表.二叉树.堆.跳表.图.Trie ...
- ffmpeg裁剪
http://it6655.com/2012/09/ffmpeg-9-2-html 1 configure参数 1 通用选项 在linux下进入终端,找到ffmpeg解压位置,输入如下命令: root ...
- CSU1011: Counting Pixels
Description Did you know that if you draw a circle that fills the screen on your 1080p high definiti ...
- KBE_创建项目和基本常识
此笔记参考官方文档 第一个项目 资产库:是每一个项目文件夹的名称,使用KBE提供的生成工具生成一个最小资产库,其中包含了很多常用的工具,默认名server_assets: res:放置一些资源(入地图 ...
- 建仓类型与对应建仓价MT4
建仓类型与对应建仓价 (Bid,Ask) 建仓类型 对应建仓价 Buy Ask+Spread Sell Bid-Spread BuyLimit Ask-Spread-StopLevel SellLim ...
- C++动态申请内存 new T()与new T[]的区别
new与delete 我们知道,new和delete运算符是用于动态分配和撤销内存的运算符. new的用法 开辟单变量地址空间: i. 如 new int ; 指开辟一个存放数组的存储空间,返回一个指 ...
- 对Spring框架的理解(转)
① spring框架是一个开源而轻量级的框架,是一个IOC和AOP容器 ② spring的核心就是控制反转(IOC)和面向切面编程(AOP) ③ 控制反转(IOC):是面向对象编程中的一种设计原则 ...
- 【Codeforces 1117C】Magic Ship
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 我们可以把这个行船的过程分解成两个过程 1.船经过时间t被风吹到了某个地方 2.船用这t时间尝试到达终点(x2,y2) 会发现如果时间t能最终 ...
- React & search & keyboard ghost
React & search & keyboard ghost DOM events https://www.w3schools.com/jsref/dom_obj_event.asp ...
- 2018/3/4 Activiti教程之流程部署篇(与Springboot整合版)二
首先我们来看下Activiti为我们自动生成的这四张用户相关的表 先看下USER表 我已经插入了一些数据,很明显,就是保存用户的信息的 看下GROUP 用户对应的分组信息 MEMBERSHIP 用户和 ...