the smallest positive number
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?
程序比较好编,就是考验计算机。最大范围也是预估的,边写边调。
尽管算对了,但方式可能不对。
def div2(n,x):
isDiv = True
for i in xrange(2,n):
if x % i != 0 :
isDiv = False
break
return isDiv
for i in xrange(2,1772146456):
if div2(21,i) == True:
print i
break
输出:
C:\webpy\webpy\Scripts\python.exe C:/pycode/euler.py
232792560
Process finished with exit code 0
后来请高手重新写了一个,这个就很正规了。
def getSmallestNum(m,n):
for j in range(1,n):
if( m*j%n ==0 ):
return m*j
return m*n
smallestNum = 1
for i in range(2,21):
if(smallestNum%i !=0):
smallestNum = getSmallestNum(smallestNum,i)
print smallestNum
the smallest positive number的更多相关文章
- 为什么实数系里不存在最小正数?(Why the smallest positive real number doesn't exist in the real number system ?)
We define the smallest positive real number as the number which is explicitly greater than zero and ...
- projecteuler Smallest multiple
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema ...
- (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 ...
- 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欧拉计划
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 ...
- a questions
1.2520 is the smallest nuber that can be diveded by each of the number from 1 to 10 without any rema ...
- 欧拉计划 NO05 ps:4题想过,好做,但麻烦,有时间补充,这题也不难!
问题重述: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without an ...
- Problem5-Project Euler
Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to ...
- Project Euler Problem5
Smallest multiple Problem 5 2520 is the smallest number that can be divided by each of the numbers f ...
随机推荐
- ASP.NET NuGet to install the mvc 5.2.2
http://www.nuget.org/packages/Microsoft.AspNet.Mvc
- C#三层开发做学生管理系统
1.定义各个层 2.添加各个层之间的引用 DAL 层调用Model BLL层调用DAL和Model UI层调用BLL和Model层 Model层供各个层调用 3.根据数据库建立实体类,每张表对应一个实 ...
- Ubuntu + Win7 双系统 重装win7后进入不了Ubuntu
机子上先有win7,然后装Ubuntu,装完Ubuntu后,开机进入Ub开机界面,里面有ubuntu,win7 loader(启动项),选择win7启动后就出现读盘错误. 天,我怎么能修复好这双系统启 ...
- mysql如何删除重复记录
方法有很多,除了最简便的, alter ignore table 表名 add UNIQUE index(字段名); 然后再将索引drop掉,这个方法外. 更加中规中矩的方法也是有的.. 比如我在网 ...
- leetcode第一刷_Word Ladder II
这道题非常难. 之前的题目我提到过一次用两个vector来做层序遍历的,就是由于这道题.要想最后恢复出单词变换的路径,就须要事先保存,依据dp中路径恢复的启示,保存的应该是一个单词的前一个变换节点.可 ...
- quick-cocos2dx学习笔记
20140603 下载quick,拉开拉链,跑setup.bat(注意,setup事就是在系统环境变量里加入QUICK_COCOS2DX_ROOT,假设不运行这个的话,启动player时会报找不到fr ...
- ViewPager 详解(四)----自主实现滑动指示条
前言:前面我们用了三篇的时间讲述了有关ViewPager的基础知识,到这篇就要进入点实际的了.在第三篇<ViewPager 详解(三)---PagerTabStrip与PagerTitleStr ...
- jquery跳出当前的each循环
break----用return false; continue --用return ture; jquery是对象链,所以$(..).each()返回的还是对象集合.each(function(){ ...
- 配置Ssh免密码登录
配置Ssh免密码登录 一个master节点,两个client节点(client1.client2) 1.所有节点创建hadoop用户,并设置密码 以root账号登录: useradd hadoop p ...
- tips [终端]
pbcopy 命令:Place standard output in the clipboard. $ pbcopy < ~/.ssh/id_rsa.pub