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 ...
随机推荐
- Selenium webdirver 操作浏览器
打开浏览器 HtmlUnit Driver 优点:不会实际打开浏览器,运行速度很快. 缺点:对JavaScript的支持不够好,有时会捕获不到页面元素. 使用:WebDriver driver=new ...
- JavaScript中依赖注入详细解析
计算机编程的世界其实就是一个将简单的部分不断抽象,并将这些抽象组织起来的过程.JavaScript也不例外,在我们使用JavaScript编写应用时,我们是不是都会使用到别人编写的代码,例如一些著名的 ...
- php命令行
转载(http://blog.jobbole.com/109093/) PHP作为一门web开发语言,通常情况下我们都是在Web Server中运行PHP,使用浏览器访问,因此很少关注其命令行操作以及 ...
- The method of type must override a superclass method解决方式
工程导入myeclipse时,出现问题提示:The method of type must override asuperclass? annotation:@Override的原因 查阅了一下资料, ...
- POJ2230 Watchcow【欧拉回路】
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 6172Accepted: 2663 Special Judge ...
- C# 网络编程之网页简单下载实现
这是根据<C#网络编程实例教程>中学到的知识实现的一个C#网页简单下载器,其中涉及到的知识主要是HTTP协议编程中相关类:HttpWebRequest类.HttpWebResponse类. ...
- c#中WebBrowser控件的使用方法
首先先来简单介绍一下webbrowser控件,这个控件是可以实现在form窗体中添加网页内容的.如图,我在form中加入了百度api,(百度地图api调用博客里有讲) 使用这个控件其实很简单 (1)第 ...
- Android(java)学习笔记254:ContentProvider使用之内容观察者(观察发出去的短信)
1.新建一个案例如下: 2. 不需要添加权限,同时这里布局文件不做修改,来到MainActivity,如下: package com.itheima.sendsmslistener; import a ...
- sql server 性能计数器
常规计数器 收集操作系统服务器的服务器性能信息,包括Processor.磁盘.网络.内存 Processor 处理器 1.1 % Processor Time指处理器用来执行非闲置线程时间的百分比.通 ...
- codevs 2451 互不侵犯(状丫dp)
/* 好神奇好神奇...表示自己要学的还很多 注意到n<=9 不是搜索就是状丫 搜索+剪枝 70分 枚举放或者不放 这里用状丫 f[i][j][k] 表示前i行 放了j个国王 i行的状态是k的方 ...