Project Euler Problem5
Smallest multiple
Problem 5
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
From problem 3, we get a list of prime factors of a number . Base on this, we get the prime factors for number from 1 to 20.
And we merge them together. The rule is, we get the largest times for each prime factor. Then we mutiply them.
The python code is as follows:
def getPrimeFactorDic(data):
dic = {}
i = 2
while i <= math.sqrt(data):
#while i <= data/2:
if data%i == 0 :
putIntoDic(dic, i)
data = (int)(data/i)
#i = 2
else:
i += 1
putIntoDic(dic, data)
return dic def putIntoDic(dic, key):
if key in dic:
dic[key] += 1
else:
dic[key] = 1 def mergeIntoDic(dic, key, value):
if key in dic:
if value > dic[key]:
dic[key] = value
else:
dic[key] = value print(getPrimeFactorDic(10))
myDic = {}
for i in range(1, 21):
tempDic = getPrimeFactorDic(i)
for key in tempDic.keys():
mergeIntoDic(myDic, key, tempDic[key])
print(myDic) mathProduct = 1
for key in myDic.keys():
mathProduct *= pow(key, myDic[key])
print(mathProduct)
Project Euler Problem5的更多相关文章
- [project euler] program 4
上一次接触 project euler 还是2011年的事情,做了前三道题,后来被第四题卡住了,前面几题的代码也没有保留下来. 今天试着暴力破解了一下,代码如下: (我大概是第 172,719 个解出 ...
- Python练习题 029:Project Euler 001:3和5的倍数
开始做 Project Euler 的练习题.网站上总共有565题,真是个大题库啊! # Project Euler, Problem 1: Multiples of 3 and 5 # If we ...
- Project Euler 9
题意:三个正整数a + b + c = 1000,a*a + b*b = c*c.求a*b*c. 解法:可以暴力枚举,但是也有数学方法. 首先,a,b,c中肯定有至少一个为偶数,否则和不可能为以上两个 ...
- Project Euler 44: Find the smallest pair of pentagonal numbers whose sum and difference is pentagonal.
In Problem 42 we dealt with triangular problems, in Problem 44 of Project Euler we deal with pentago ...
- project euler 169
project euler 169 题目链接:https://projecteuler.net/problem=169 参考题解:http://tieba.baidu.com/p/2738022069 ...
- 【Project Euler 8】Largest product in a series
题目要求是: The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × ...
- Project Euler 第一题效率分析
Project Euler: 欧拉计划是一系列挑战数学或者计算机编程问题,解决这些问题需要的不仅仅是数学功底. 启动这一项目的目的在于,为乐于探索的人提供一个钻研其他领域并且学习新知识的平台,将这一平 ...
- Python练习题 049:Project Euler 022:姓名分值
本题来自 Project Euler 第22题:https://projecteuler.net/problem=22 ''' Project Euler: Problem 22: Names sco ...
- Python练习题 048:Project Euler 021:10000以内所有亲和数之和
本题来自 Project Euler 第21题:https://projecteuler.net/problem=21 ''' Project Euler: Problem 21: Amicable ...
随机推荐
- 初学Hadoop之单机模式环境搭建
本文仅作为学习笔记,供大家初学Hadoop时学习参考.初学Hadoop,欢迎有经验的朋友进行指导与交流! 1.安装CentOS7 准备 CentOS系统镜像CentOS-7.0-1406-x86_64 ...
- Alpha 冲刺七
团队成员 051601135 岳冠宇 051604103 陈思孝 031602629 刘意晗 031602248 郑智文 031602234 王淇 会议照片 项目燃尽图 项目进展 无进展!!!! 项目 ...
- Jmeter使用笔记之函数
用Jmeter才做了一个项目的测试,就不得不对函数这部分吐槽一下,真是有点弱,难怪大多数人不用这个功能,不过如果用的好也是很方便的,以下慢慢说. 一.BeanShell函数 在测试中遇到了时间戳的加减 ...
- jQuery~DOM基础操作
操作DOM 1.什么是DOM:document object model文档对象模型 2.树形结构 3.什么是节点(node):DOM结构中最小单位,元素.文本.属性...创建节点 var $div ...
- Android Manifest文件
Manifest文件内容 1.自定义权限(Permission) : <permission android:description="string resource" a ...
- wordpress 点击文章图片 不能编辑(chrome下面) wordpress Uncaught DOMException: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 1.
说明:在chrome下面,编辑文章插入的图片,点击到图片上面,没有菜单显示. 报错: tinymce.min.js:10 Uncaught DOMException: Failed to execut ...
- 怎么把焦点放在RichEdit的最后一行
急急急!!!!如何把焦点放在RichEdit的最后一行!! 请高手指点,在线等!!!!当添加到出现滚动条时焦点就不会往下了,怎么把焦点移到最后一行 RichEdit-> Lines-> A ...
- robotframework+Selenium2Library 模态窗口的处理
原文链接:https://www.cnblogs.com/zuola/p/5750018.html 所谓模态窗口,就是指除非采取有效的关闭手段,用户的鼠标焦点或者输入光标将一直停留在其上的对话框. ...
- python中安装pandas
在运行网上找的代码时,报错:ImportError: No module named 'pandas',解决:安装pandas安装过程:(因为网上教程有的说用pip命令行安装:有的直接下载安装包,然后 ...
- python315题
目录 Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Python的 ...