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的更多相关文章

  1. 为什么实数系里不存在最小正数?(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 ...

  2. projecteuler Smallest multiple

    2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema ...

  3. (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 ...

  4. 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 ...

  5. 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 ...

  6. a questions

    1.2520 is the smallest nuber that can be diveded by each of the number from 1 to 10 without any rema ...

  7. 欧拉计划 NO05 ps:4题想过,好做,但麻烦,有时间补充,这题也不难!

    问题重述: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without an ...

  8. Problem5-Project Euler

    Smallest multiple   2520 is the smallest number that can be divided by each of the numbers from 1 to ...

  9. Project Euler Problem5

    Smallest multiple Problem 5 2520 is the smallest number that can be divided by each of the numbers f ...

随机推荐

  1. Flask+Mysql搭建网站之网页设计

    不得不说,本人极度讨厌网页设计,感觉太麻烦了.不过整好啦还蛮有成就感的. 关于网页设计,现在流行的是扁平化设计. http://www.bootcss.com/ http://www.bootcss. ...

  2. K - The Unique MST - poj 1679

    题目的意思已经说明了一切,次小生成树... ****************************************************************************** ...

  3. Ajax之 beforeSend和complete longind制作

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; min-height: 18.0px } p.p2 { margin: 0 ...

  4. IOS实现小型计算器

    作为一名初学者,编辑一款能够在IOS操作系统上运行的计算器是一件很值得自豪的事情,网络上虽然后很多相关的文章和代码,功能也很强大但是我感觉相关的计算器比加复杂,晦涩难懂,所以我想通过这个小小的计算器, ...

  5. HDU1159 && POJ1458:Common Subsequence(LCS)

    Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...

  6. 10 Questions To Make Programming Interviews Less Expensive--reference

    Conducting Interview is not cheap and costs both time and money to a company. It take a lot of time ...

  7. Linux最大文件打开数

    介绍 在Linux下有时会遇到Socket/File : Can't open so many files的问题.其实Linux是有文件句柄限制的,而且Linux默认一般都是1024(阿里云主机默认是 ...

  8. Myeclipse中点(.)不出来方法或者属性?

  9. css中同时用头部引入和外部引入对同一个标签进行样式设置,哪一个优先级高。

    这段是html中的代码 <!doctype html> <html lang="en"> <head> <meta charset=&qu ...

  10. css书写步骤

    CSS整体书写步骤1:CSS RESET 重置2:CSS GLABAL 全局属性3: CSS分模块属性,(先写默认样式和设计图相差最大的部分,先大块布局,后细致调整) <style>/*C ...