Project Euler Problem 5-Smallest multiple
对每个数字分解素因子,最后对每个素因子去其最大的指数,然后把不同素因子的最大指数次幂相乘,得到的就是最小公倍数
python不熟练,代码比较挫
mp = {}
def process(n):
i = 2
while i*i <= n:
cnt = 0
if n%i == 0:
while n%i == 0:
cnt += 1
n /= i
if i in mp:
mp[i] = max(mp[i], cnt)
else:
mp[i] = cnt
i += 1
if n > 1:
if n in mp:
mp[n] = max(mp[n], 1)
else:
mp[n] = 1
for i in range(2,21):
process(i)
res = 1
for x in mp:
res *= (x**mp[x])
print res
Project Euler Problem 5-Smallest multiple的更多相关文章
- 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 ...
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
- Project Euler problem 62
题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 ...
- Project Euler problem 63
这题略水啊 首先观察一下. 10 ^ x次方肯定是x + 1位的 所以底数肯定小于10的 那么我们就枚举1~9为底数 然后枚举幂级数就行了,直至不满足题目中的条件即可break cnt = 0 for ...
- Project Euler problem 61
题意很明了. 然后我大概的做法就是暴搜了 先把每个几边形数中四位数的处理出来. 然后我就DFS回溯着找就行了. 比较简单吧. #include <cstdio> #include < ...
- Project Euler problem 68
题意须要注意的一点就是, 序列是从外层最小的那个位置顺时针转一圈得来的.而且要求10在内圈 所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可. #include <iostr ...
- Project Euler Problem 675
ORZ foreverlasting聚聚,QQ上问了他好久才会了这题(所以我们又聊了好久的Gal) 我们先来尝试推导一下\(S\)的性质,我们利用狄利克雷卷积来推: \[2^\omega=I\ast| ...
- Project Euler Problem (1~10)
1.If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. Th ...
- Project Euler Problem 26-Reciprocal cycles
看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...
随机推荐
- list的基本使用
转自:https://www.cnblogs.com/BeyondAnyTime/archive/2012/08/10/2631191.html vector :vector和built-in数组类似 ...
- shared_from_this bad_weak_ptr的原因
原因:创建类A的对象的时候没有用智能指针包裹,而是直接new的裸指针. enable_from_this 的使用与实现原理说明: shared_from_this()是enable_shared_fr ...
- mysql实现行拼接、列拼接
举例:有t_person表如下: 一.mysql行拼接: 拼接某一行: 无分隔符:select CONCAT(id,idcard,`status`,content) from t_perso ...
- DirectX11笔记(一)--配置DirectX工程
原文:DirectX11笔记(一)--配置DirectX工程 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/u010333737/article/d ...
- C++ 之手写memcpy
#include<iostream>#include<cstdio>using namespace std; void* mymemcpy(void* dst, const v ...
- 初探uni-app
第一步:下载 第二步:安装 第三步:创建项目 第四步:项目目录 项目运行 项目效果为 打包为原生App(云端) 运行打包 使用vue 效果如下,并不好看 使用代码如下 未完,待续.... 就是对着官网 ...
- LeetCode141 Linked List Cycle. LeetCode142 Linked List Cycle II
链表相关题 141. Linked List Cycle Given a linked list, determine if it has a cycle in it. Follow up:Can y ...
- Servlet各种接口和类
http://blog.csdn.net/jediael_lu/article/details/25036019
- CSS user-select文本是否可复制
1. 概述 1.1 说明 在项目过程中,有时候需要网页中内容信息不可被复制进行保护数据信息,故可使用css属性user-select进行控制用户能否选中文本. 1.2 语法 user-select : ...
- iOS 9 学习系列:UIStack View
http://www.cocoachina.com/ios/20150921/13492.html 在 iOS9 中,Apple 引入了 UIStackView,他让你的应用可以通过简单的方式,纵向或 ...