博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
the smallest positive number
阅读量:7113 次
发布时间:2019-06-28

本文共 832 字,大约阅读时间需要 2 分钟。

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 isDivfor 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*nsmallestNum = 1for i in range(2,21):    if(smallestNum%i !=0):        smallestNum = getSmallestNum(smallestNum,i)print smallestNum

 

转载地址:http://gfghl.baihongyu.com/

你可能感兴趣的文章
【Android】RxJava的使用(四)线程控制 —— Scheduler
查看>>
极限编程 (Extreme Programming) - 迭代计划 (Iterative Planning)
查看>>
小程序外卖购物车 直接就能用~
查看>>
Python版设计模式之监听者模式
查看>>
[Spring Security 5.2.0 翻译] 8 Architecture and Implementation
查看>>
使用 Sphinx 撰写技术文档并生成 PDF 总结
查看>>
Fastjson的基本使用方法大全
查看>>
SSH 超时设置
查看>>
webpack 最简打包结果分析
查看>>
NLPIR:数据挖掘深度决定大数据应用价值
查看>>
Flex 布局教程
查看>>
GET和POST两种基本请求方法的区别
查看>>
Webpack4 学习笔记 - 01:webpack的安装和简单配置
查看>>
二)golang工厂模式
查看>>
React 教程:快速上手指南
查看>>
Python 的 heapq 模块源码分析
查看>>
Jitsi快捷安装
查看>>
区块链技术的基本特点
查看>>
阿里云容器服务DaemonSet实践
查看>>
一个游戏拨账系统的数据库结算设计
查看>>