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?

先从2-10分解质因子来考虑:

2 = 2
3 = 3
4 = 2*2
5 = 5
6 = 2*3
7 = 7
8 = 2*2*2
9 = 3*3
10 = 2*5

而最小的2520的质因子为:2*2*2*3*3*5*7。如何利用2-10的质因子构造出2520的质因子是关键。

a = {}  # 字典,key是质因子,value是质因子个数
for i in range(2,21): # 从2-20开始遍历
temp = {} #
while i!= 1:
for j in range(2,21):
if i % j == 0:
temp.setdefault(j,0)
temp[j]+=1
i /= j
break
for k in temp:
if a.setdefault(k, 0) < temp[k]:
a[k]=temp[k]
b = 1
for i in a:
b *= i**a[i] print(b)

Problem 5: Smallest multiple的更多相关文章

  1. Smallest multiple

    problem 5:Smallest multiple 题意:求最小的正数,使得其可以被1-20整除 代码如下: #ifndef PRO5_H_INCLUDED #define PRO5_H_INCL ...

  2. (Problem 5)Smallest multiple

    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema ...

  3. projecteuler Smallest multiple

    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema ...

  4. [LeetCode&Python] Problem 908. Smallest Range I

    Given an array A of integers, for each integer A[i] we may choose any x with -K <= x <= K, and ...

  5. Python练习题 033:Project Euler 005:最小公倍数

    本题来自 Project Euler 第5题:https://projecteuler.net/problem=5 # Project Euler: Problem 5: Smallest multi ...

  6. POJ 1465 Multiple (BFS,同余定理)

    id=1465">http://poj.org/problem?id=1465 Multiple Time Limit: 1000MS   Memory Limit: 32768K T ...

  7. Enlisting multiple 1-phase aware participants in the same transaction

    In some cases it may be necessary to enlist participants that aren't two-phase commit aware into a t ...

  8. 【Leetcode_easy】908. Smallest Range I

    problem 908. Smallest Range I solution: class Solution { public: int smallestRangeI(vector<int> ...

  9. 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Section 4 The Central Limit Theorem

    Stat2.2x Probability(概率)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...

随机推荐

  1. 小程序配置tabbar

    app.json中添加tabbar "tabBar": { "color": "#a9b7b7", //未选中字体颜色 "sele ...

  2. web 后台返回json格式数据的方式(status 406)

    1.在类上使用注解 @RestController public class HttpComentInterface { } 2.在方法是使用注解  @ResponseBody @RequestMap ...

  3. windows平台 python生成 pyd文件

    Python的文件类型介绍: .py       python的源代码文件 .pyc     Python源代码import后,编译生成的字节码 .pyo     Python源代码编译优化生成的字节 ...

  4. ES5 & ES6 基础

    一.什么是ES5 附上一览表 (5.1中文 (2011.6)): http://lzw.me/pages/ecmascript/ (5.1英文PDF):http://www.ecma-internat ...

  5. redhat 7 配置源

    http://blog.51cto.com/eagle2014/1434305 一.准备工作 Vmware Workstation 10.0虚拟机软件(http://www.vmware.com/pr ...

  6. jsp的page、request、session、application四个作用域的作用

    1.page作用域也是最小的作用域,它只能在当前页面中使用. 2.request作用域主要是发送请求,但只能在两个页面之间发送一次请求. 3.session作用域是一个会话,也就是一个浏览器,意思是说 ...

  7. 【Redfin SDE intern】跪经

    萌新的面试第一弹 Redfin是我求职生涯中的第一家,第一个电面,第一个onsite.除了结果不好,其他过程都很好... 春节当天风风火火去西雅图面试,之前分配的五个面试官其中有两个中国人,然而全部被 ...

  8. 关于Python的一些看法

    我是一个学新闻传播的编程新人,对于电脑这一方面,我是真的有一些一窍不通啊~选择Python语言程序设计的原因也是因为出于Python对未来专业可能会起到帮助考虑(因为未来我的专业会涉及到一些大数据抽查 ...

  9. JRebel springboot部署idea

    JRebel springboot部署idea     http://127.0.0.1:8888/88414687-3b91-4286-89ba-2dc813b107ce   ctrl+shift+ ...

  10. shell脚本学习之实例列举

    1.用shell写一个从1加到100的程序: 方法一: #!/bin/bashsum=0for i in {1..100}do   let sum+=$idone   echo $sum 方法二: # ...