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 中 MongoDB 使用指南
一.引入MongoDB Java Driver包 如果需要操作MongoDB的Java项目是一个Maven项目,可以在依赖中加上以下的配置. <dependencies> <depe ...
- 安装redis,含安装步骤和安装中出现的详细错误分析
1.wget http://download.redis.io/releases/redis-2.8.13.tar.gz 2.解压文件 tar -zxvf redis-2.8.13.tar.gz 3. ...
- Robotium--takeScreenshot(截图)
在Robotium中,截图的方法时调用takeScreenshot(). 但有使用你会发现明明代码里调用了solo.takeScreenshot(),但却没有截图成功,那是因为被测试的应用没有SD卡的 ...
- Android EditText的使用及值得注意的地方
Android上有很多输入法应用,每种输入法都有各自的特点,输入法多数时候是和EditText配合使用,结合我自己的亲身实践分享一下使用EditText过程中遇到的一些问题及解决方法. 设置默认输入法 ...
- String对象之间的比较
public class StringTest { @Test public void test01() { int a = 50; // 基本数据类型比较的是值 int b = 50; System ...
- android系统360浏览器使用append动态添加元素出现黑色错乱背景
去掉样式 backface-visibility:hidden;
- CSS权威指南学习笔记系列(1)CSS和文档
题外话:HTML是一种结构化语言,而CSS是它的补充:这是一种样式语言.CSS是前端三板斧之一,因此学习CSS很重要.而我还是菜鸟,所以需要加强学习CSS.这个是我学习CSS权威指南的笔记,如有不对, ...
- 2015-09-28Javascript(一)
- solr和mongodb比较
solr非常灵活,虽然mongodb添加索引查询速度比较快,但是solr查询比mongodb更加灵活,所以需要获取mongodb的oplog,实时将oplog中的数据推送到solr中 oplog A ...
- php捕获异常的处理
try { $result = *} catch (Exception $e) { $result = $e; } 如果try里面报异常,$result = ...