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 ...
随机推荐
- Java中的不可变类
概念:不可变类的意思是创建该类的实例后,该实例的属性是不可改变的.java中的8个包装类和String类都是不可变类.所以不可变类并不是指该类是被final修饰的,而是指该类的属性是被final修饰的 ...
- spring-mvc.xml配置文件出错
在整合ssm三大框架的时候,配置spring-mvc.xml的文件的 <mvc:default-servlet-handler/> <mvc:annotation-driven /& ...
- WIndows系统下mysql-noinstall安装配置
环境: Windowsmysql-noinstall-5.0.37-win32.zip 一.下载MySQL http://www.mysql.com/downloads 二.安装过程 1.解压缩mys ...
- Jenkins的错误“error fetching remote repo origin”的问题解决
错误如上,解决方法收集,可以尝试以下方法: http://stackoverflow.com/questions/38391601/jenkins-error-error-fetching-remot ...
- [置顶] flex4事件监听与自定义事件分发(三)
1.我们来说一下自定义事件子类.什么时候创建新的事件类以及怎么创建. (1)说一下,我们什么时候需要自定义事件类.举例说明,在flex中事件的基类是Event,而当我们点击某个按钮或者是单击某个组件的 ...
- BaseAdapter的ArrayIndexOutOfBoundsException
最近写一个listView中多个listItem布局时,convertView缓存及使用,类似微信的聊天界面的listView,报了一个异常: 11-25 15:51:49.076: E/InputE ...
- C++获得系统路径
源码: [cpp] view plaincopy #include <Shlobj.h> #include <stdio.h> #include <locale.h> ...
- floor() 和 ceil()函数
在C语言的库函数中,floor函数的语法例如以下: #include <math.h> double floor( double arg ); 功能: 函数返回參数不大于arg的最大整数. ...
- 用switch判断月份的练习
import java.util.Scanner; public class SwitchTest01 { public static void main(String[] args) { Syste ...
- 使用nice命令调整进程优先级
Adjusting Process Priority with nice When Linux processes are started, they are started with a spe ...