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. redis序列化

    private void setSerializer(StringRedisTemplate template) { Jackson2JsonRedisSerializer jackson2JsonR ...

  2. .NET、C#和ASP.NET、ASP.NET MVC四者之间的区别

    什么是.NET? .NET是微软公司下的一个开发平台,.NET核心就是.NET Framwork(.NET框架)是.NET程序开发和运行的环境,在这个平台下可以用不同的语言进行开发,因为.NET是跨语 ...

  3. 基于vue 、vue-router 、firebase的todolist小项目

    第一次写博客,都不知道改怎么写的好. 本着一颗学习的心,也希望一段时间后再回来在看看自己写的代码,会不会让自己有种不忍直视的念头 *-* 还是先上图吧~ 这是首页,主要是展示所有的列表页面,可以通过输 ...

  4. ubuntu1604 golang环境

    copy来的,这里记录一下 1. 升级系统: sudo apt-get upgrade 2. 安装docker 下载docker-ce: https://download.docker.com/lin ...

  5. 开发者的自测利器-Hprof命令(寻找cpu热点)

    测试代码: public class HProfTest { public void slowMethod() { try { Thread.sleep(1000); } catch (Excepti ...

  6. vue1.0配置路由

    1,//创建 router 实例 var router = new VueRouter() 2,//components下新建home.vue组件,并在app.vue中引入模块: import hom ...

  7. vue-组件注册

    <div id="app-7"> <ol> <!-- 现在我们为每个 todo-item 提供 todo 对象 todo 对象是变量,即其内容可以是动 ...

  8. C++文件输入和创建

    #include <fstream> //头文件 ifstream inf; ofstream ouf; inf.open("zy4.txt", ios::out); ...

  9. laravel5.5 env

    env 函数 读取的变量里面带有 # 号的情况下 数据会丢失

  10. WEEK1

    #变量 var1: name = input('name:') age = input('age:) job = input('job:) salary = input('salary:) info ...