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 ...
随机推荐
- 小白鼓捣GIT的心得
这篇文章写给那些之前没接触过git的开发人员,算是一个参考吧,希望能有所帮助,我也会尽量写的详细. 今天刚开通了博客,趁着兴致,想着把积累已久的git问题也一并搞懂吧,于是乎吃完饭开始鼓捣,从下载GI ...
- 机器学习实战__安装python环境
环境:win7 64位系统 第一步:安装python 1.下载python2.7.3 64位 msi 版本(这里选择了很多2.7的其他更高版本导致安装setuptools失败,也不知道是什么原因,暂时 ...
- 如何用命令将本地项目上传到git
1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...
- javac 命令行使用总结
先给出参考的两个链接,然后再总结: 内容:使用javac 指定编译多个目录下java文件 链接:http://zhidao.baidu.com/link?url=W5ZERu8_ouGD-L_JH0v ...
- Demon_游戏登录界面(具备账号密码输入功能)
using UnityEngine; using System.Collections; using UnityEngine.UI;// public class LoginButton : Mono ...
- 苹果Swift编程语言新手教程【中国版】
Swift代码语言教程:在刚刚过去的WWDC2014大会上,苹果公司新公布了一种编程语言Swift.据悉.Swift语言继承了C语言以及Objective-C的特性,且克服了C语言的兼容性问题.对于广 ...
- JBoss 系列九十六:JBoss MSC - 简介及一个简单演示样例
什么是 JBoss MSC JBoss MSC 即 JBoss Modular Service Container,是第三代 JBoss 产品 JBoss 7和WildFfly的内核,JBoss MS ...
- 分层模型的典型应用和FishiGUI的分层模型
分层模式的典型应用: 对于交互类型的软件也能够採用分层模式来进行架构分析,一般来说将交互性的软件分为三个层次比較合适:显示层的职责是为了显示信息,应用逻辑层封装那些一般不easy发生变化的核心逻辑,而 ...
- 子查询in和表连接效率
在数据查询时,尽量减少in子查询而使用表连接的方式进行,效率更高.
- codevs 2995 楼房
/*暴力30分*/ #include<iostream> #include<cstring> #include<cstdio> #include<map> ...