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 ...
随机推荐
- 11th 回忆整个学期——告学弟学妹
告诉后来的学弟学妹,不要因为艰难而却步,坚持下去才知道,山的对面是什么.很多东西或许一开始看起来是无用,甚至无意义的,但是努力去做,你才知道价值所在.不要等一切结束了,才懂得自己错过了什么.
- Docker(五)-Dcoker容器
简单的说,容器是独立运行的一个或一组应用,以及它们的运行态环境. 如果把镜像看成面向对象中的 类 的话,那么容器就是 类 的实例化 对象. 容器 启动容器 启动容器有两种方式,一种是基于镜像新建一个容 ...
- button 和 submit 的区别
表单提交中button和submit的区别submit是button的一个特例,也是button的一种,它把提交这个动作自动集成了,submit和button,二者都以按钮的形式展现,看起来都是按钮, ...
- tp3.2.3运用phpexcel将excel文件导入mysql数据库
1,下载PHPExcel 2,配置将下载好的PHPExcel文件与PHPExcel.php 放到thinkphp 根目录 include/Library/Org/Util/下面 3,同时将PHPExc ...
- Java NIO 详解(一)
一.基本概念描述 1.1 I/O简介 I/O即输入输出,是计算机与外界世界的一个借口.IO操作的实际主题是操作系统.在java编程中,一般使用流的方式来处理IO,所有的IO都被视作是单个字节的移动,通 ...
- Python Django性能测试与优化指南
摘要:本文通过一个简单的实例一步一步引导读者对其进行全方位的性能优化.以下是译文. 唐纳德·克努特(Donald Knuth)曾经说过:“不成熟的优化方案是万恶之源.”然而,任何一个承受高负载的成熟项 ...
- BZOJ 2226 [Spoj 5971] LCMSum 最大公约数之和 | 数论
BZOJ 2226 [Spoj 5971] LCMSum 这道题和上一道题十分类似. \[\begin{align*} \sum_{i = 1}^{n}\operatorname{LCM}(i, n) ...
- Python【unittest】模块
[unittest]模块是python3.5中的一个内置模块 1.python文件导入[unittest]模块 import unittest 2.定义一个测试用例类,继承[unittest.Test ...
- [Java] I/O底层原理之二:网络IO及网络编程
首先我们来看一下当访问一个域名时它的过程 查找 DNS 首先,浏览器检查缓存中有没有 浏览器缓存中没有,则查找操作系统中有没有配置这个对应关系 如果操作系统中也没有,则去 DNS 查找,即发送DNS报 ...
- 小贾漫谈——Java反射
一.Class的API 二.测试使用的JavaBean class Admin{ //字段 public String userName; public String pwd; private int ...