Problem 5: Smallest multiple
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的更多相关文章
- Smallest multiple
problem 5:Smallest multiple 题意:求最小的正数,使得其可以被1-20整除 代码如下: #ifndef PRO5_H_INCLUDED #define PRO5_H_INCL ...
- (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 ...
- projecteuler Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema ...
- [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 ...
- Python练习题 033:Project Euler 005:最小公倍数
本题来自 Project Euler 第5题:https://projecteuler.net/problem=5 # Project Euler: Problem 5: Smallest multi ...
- POJ 1465 Multiple (BFS,同余定理)
id=1465">http://poj.org/problem?id=1465 Multiple Time Limit: 1000MS Memory Limit: 32768K T ...
- 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 ...
- 【Leetcode_easy】908. Smallest Range I
problem 908. Smallest Range I solution: class Solution { public: int smallestRangeI(vector<int> ...
- 加州大学伯克利分校Stat2.2x Probability 概率初步学习笔记: Section 4 The Central Limit Theorem
Stat2.2x Probability(概率)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...
随机推荐
- Java 的 clone 方法 && 浅复制和深复制
1 Java中对象的创建过程 java创建对象的方式有以下两种: (1)使用new操作符创建一个对象 (2)使用clone的方法复制一个对象,(在Java中,clone是Object类的protect ...
- 数据类型 varchar 和 uniqueidentifier 在 add 运算符中不兼容
select '<a href="/'+a.id +'" title="'+ a.title +'">'+a.Title+'</a>' ...
- webpack 4.X 基础编译
webpack4.x的打包已经不能用webpack 文件a 文件b的方式,而是直接运行webpack --mode development或者webpack --mode production,这样便 ...
- JS 自由变量---JS 学习笔记(三) 补充
自由变量:在 A 中作用域要用到的变量 x,并没有在 A 中声明,要到别的作用域中找到他,这个变量 x 就是自由变量.代码示例如下: var x = 20; function A (b) { ret ...
- python 在字典中添加键值对的方法。
list 添加元素的方法是 list.append(a).将 a 添加到 list 里. dict 添加元素的方法是 dict.update(dict2).意为,将 dict2 的内容添加到 di ...
- PowerDesigner大小写转换
在菜单栏找到:Tools-->Execute Commands --> Edit/Run Script 快捷键:Ctrl+Shift+X 输入下边的代码就可以了.(UCase大写 LCas ...
- vim 复制粘贴
首先进入块模式 Ctrl+ v 使用按键j/k/h/l进行选中多列 使用按键y进行复制 在insert模式下:使用按键p进行粘贴
- ACM-ICPC2018南京赛区 Mediocre String Problem
Mediocre String Problem 题解: 很容易想到将第一个串反过来,然后对于s串的每个位置可以求出t的前缀和它匹配了多少个(EXKMP 或者 二分+hash). 然后剩下的就是要处理以 ...
- mvc5之文件上传
在写这篇博客之前,被网上的博客坑了一个遍. 浪费了很多的时间 最后还是靠一位兄弟解决的问题,不得不说,虽然网上资源多.但是大多数都是水货.如果那些人可以解决你的问题,那我这里明显就没用了,除非你和我一 ...
- canal demo搭建全记录
一.环境介绍 canal是阿里开源的中间件,主要用于同步mysql数据库变更.具体参见:https://github.com/alibaba/canal/releases 搭建环境: vmware c ...