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 ...
随机推荐
- heap_sort
(from wikipedia) 构建步骤: 建成一个大顶堆 第一个元素依次和最后一个元素交换,由于交换后新的堆顶元素可能违反大根堆的性质,因此需要对当前无序区(1,2,...,n-1)调整为新堆 不 ...
- UVA - 11468 (AC自动机+动态规划)
建立AC自动机,把AC自动机当做一张图,在上面跑L个节点就行了. 参考了刘汝佳的代码,发现可能有一个潜在的Bug--如果模式串中出现了没有指定的字符,AC自动机可能会建立出错. 提供一组关于这个BUG ...
- 实验九 FBG 团队项目需求改进与系统设计
任务一 A.<项目需求规格说明书>分析 根据老师的指导以及本周所学的OOA,分析改进上周编写的<项目需求规格说明书>,发现需求项目书UML图例描述不够完善,仅仅是用例图没办法更 ...
- angular + socket.io+nodejs
一.服务器端: 基本和nodejs工程相同 https://www.cnblogs.com/xuanmanstein/p/10509445.html 安装socket.io npm i --save ...
- 三个水杯——java,广度优先搜索
题目如下: 21-三个水杯 内存限制:64MB 时间限制:1000ms 特判: No通过数:51 提交数:137 难度:4 题目描述: 给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个 ...
- jquary高级和ajax
jquary高级: 1.动画 1.三种方式显示与隐藏元素 1.默认显示和隐藏的方式 1.show([speed],[easing],[fn]):显示 [speed],[easing],[fn] spe ...
- MySQL ERROR 1130 (HY000): Host '192.168.1.8' is not allowed to connect to this MySQL server
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.8' IDENTIFIED BY 'www.linuxidc.com' WITH GRANT OPTI ...
- redist命令操作(三)--集合Set,有序集合ZSet
1.Redis 集合(Set) 参考菜鸟教程:http://www.runoob.com/redis/redis-sets.html Redis 的 Set 是 String 类型的无序集合.集合成员 ...
- Vue2.0增删改查案例(Vue+Less+LocalStorage)
本人写的小程序,功能还在完善中,欢迎扫一扫提出宝贵意见! Vue+Less+LocalStorage 安装Less:npm install less less-loader --s ...
- npm run build 打包后,如何运行在本地查看效果(Nginx服务)
这段时间,研究了一下vue 打包的很慢的问题.但是当我 npm run build 打包后,在本地查看效果的时候,活生生被我老大鄙视了,因为我打开了XAMPP.他说:你怎么不用Nginx啊?用这个一堆 ...