Highly divisible triangular number
我的那个暴力求解,太耗时间了。
用了网上产的什么因式分解,质因数之类的。确实快!还是数学基础不行,只能知道大约。
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?
from math import sqrt
import time
def natSum(n):
x = 1
count = 0
sum = 0
while count <= n:
sum += x
count = 0
for i in range(1,int(sqrt(sum))+1):
if sum % i == 0:
count += 2
if sqrt(sum)==int(sqrt(sum)):
count -= 1
print x,sum,count,n
x += 1
natSum(500)
'''
start=time.time()
now=2
num=1
t = 0
while t <= 500 :
num=num+now
now+=1
t=0
for x in range(1,int(sqrt(num))+1):
if num%x==0:
t+=2
if sqrt(num)==int(sqrt(num)):
t=t-1
print num
print num
print time.time()-start
'''
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 ...
- projecteuler---->problem=12----Highly divisible triangular number
title: The sequence of triangle numbers is generated by adding the natural numbers. So the 7th trian ...
- Project Euler Problem 12-Highly divisible triangular number
最直接的想法就是暴力搞搞,直接枚举,暴力分解因子.再好一点,就打个素数表来分解因子.假设num=p1^a1p2^a2...pn^an,则所有因子个数为(a1+1)(a2+1)...(an+1). 再好 ...
- PE刷题记
PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...
- Python练习题 040:Project Euler 012:有超过500个因子的三角形数
本题来自 Project Euler 第12题:https://projecteuler.net/problem=12 # Project Euler: Problem 12: Highly divi ...
- Triangular Sums
描述 The nth Triangular number, T(n) = 1 + … + n, is the sum of the first n integers. It is the number ...
- Triangular numbers
http://codeforces.com/problemset/problem/47/A Triangular numbers time limit per test 2 seconds memor ...
- Triangular Sums 南阳acm122
Triangular Sums 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 The nth Triangular number, T(n) = 1 + … + n ...
- CF47A Triangular numbers
CF47A Triangular numbers 题意翻译 给定一个数n,问你是否存在一个整数i,满足i*(i+1)/2=n. 若存在,输出"YES",否则输出"NO&q ...
随机推荐
- 微博广告推荐中有关Hadoop的那些事
一.背景 微博,一个DAU上亿.每日发博量几千万的社交性产品,拥有庞大的数据集.如何高效得从如此规模的数据集中挖掘出有价值的信息,以增强用户粘性,提高信息传播速度,就成了重中之重.因此,我们引入了ha ...
- Drainage Ditches - poj 1273(网络流模板)
题意:1是源点,m是汇点,求出来最大流量,没什么好说的就是练习最大流的模板题 ************************************************************* ...
- 1033 - Merging Maps
Pictures taken from an airplane or satellite of an ar ea to be mapped are often of sufficiently high ...
- [Angular 2] Passing Observables into Components with Async Pipe
The components inside of your container components can easily accept Observables. You simply define ...
- c#中WebBrowser控件的使用方法
首先先来简单介绍一下webbrowser控件,这个控件是可以实现在form窗体中添加网页内容的.如图,我在form中加入了百度api,(百度地图api调用博客里有讲) 使用这个控件其实很简单 (1)第 ...
- 如何为Myeclipse手工添加dtd支持
一.引言 在MyEclipse中开发三大框架的项目时候经常会写一些配置的xml文件,例如:Struts2的struts.xml和Hibernate的hibernate.cfg.xml.Spring的a ...
- 两台Linux机之间传送文件
最近实验室里接管了一台服务器,经常需要用到服务器与自己主机之间进行文件传输,因此,在此介绍一下两台Linux主机之间的一些操作,方便后来者. 1. Linux.Windows主机远程访问Linux服务 ...
- 检查主机是否存活的shell脚本
#!/bin/bash PREFIX= num= " ]; do echo -en "Pinging ${PREFIX}.${num}..." >& &qu ...
- openvpn server部署笔记
openvpn server 部署 1.准备 安装依赖 yum -y install gcc gcc-c++ openssl-devel openssl pam-devel 2.安装 lzo cd / ...
- C# 面向对象 , 类与对象
一,类的字段 类的字段, 就是类里面的 数据. 二,类的方法 1 , 函数的重载 , 如何判断: 是由两个或多个同名函数组成的,但是函数要有不同的参数.或个数.(参数 是函数的输入的东西) shu ...