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. Xilinx Vivado的使用详细介绍(4):Zedboard+vivado之流水灯(加SDK)

    Vivado+zedboard之初学流水灯 Author:zhangxianhe 环境:vivado 2016.3(已验证适用于2015.4) 开发板:Zedboard version xc7z020 ...

  2. Kotlin 类和对象

    类定义 Kotlin 类可以包含:构造函数和初始化代码块.函数.属性.内部类.对象声明. Kotlin 中使用关键字 class 声明类,后面紧跟类名: class Runoob { // 类名为 R ...

  3. 给web请求加遮罩动画

    效果预览: css: /*#fountainG{ position:relative; margin:10% auto; width:240px; height:29px }*/ #fountainG ...

  4. Java核心技术卷一 · 笔记(1)

    目录 1.java的关键术语 2.==和equals 3.空串与 Null 串 4.构建字符串 5.封装 6.对象的三个主要特性 7.依赖(dependence).聚合(aggregation).继承 ...

  5. XV Open Cup named after E.V. Pankratiev. GP of Central Europe (AMPPZ-2014)--B.Petrol

    多源最短路+并查集 #include <bits/stdc++.h> using namespace std; #define rep(i, j, k) for (int i = int( ...

  6. 思科模拟器PacketTracer7--利用一台交换机和2台pc互连构成小型局域网

    实验二—2 实验工具:思科模拟器PacketTracer7(可在思科官网下载,免费) 实验设备: 交换机一台,PC两台,直连线或选择自动匹配 实验步骤: 一.配置网络拓扑图 连线可选择连通线或闪电符号 ...

  7. 3.4 自动测试初步《精通ASP.NET MVC 5》

    概述 ASP.NET MVC 框架已被设计成易于建立自动测试,并易于采用诸如测试驱动开发(TDD)等的开发方法学.ASP.NET MVC 为自动化测试提供了一个理想平台. 从广义上讲,当今的 Web ...

  8. ckeditor文本对齐方式添加,图片上传

    最近用的AdminBSBMaterialDesign-master模板,里边用到了ckeditor编辑器 但发现里边没有基本的文本对齐方式,找了好一会,好多方法都不管用,最后在config.js中添加 ...

  9. Introduction and use of Cookie and Session(Cookie&Session的介绍和使用)

    一.Cookie 1.什么是Cookie? Cookie是HTTP协议的规范之一,它是服务器和客户端之间传输的小数据. 首先由服务器通过响应头把Cookie传输给客户端,客户端会将Cookie保存起来 ...

  10. Response重定向实现参数隐藏

    最近在弄一个SSH项目,前期已经做好了,现在的需求是进行单点登陆实现,涉及到重定向跳转(带有参数那种)情况,但是不能在地址栏上出现参数的信息,需要进行参数的隐藏跳转.由于时间比较急,本人没来得及开发一 ...