[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[原创代码] 欧拉计划005-求最小同时都能被1-20整除的数

本帖最后由 codegay 于 2016-4-13 15:18 编辑

欧拉计划005-求最小同时都能被1-20整除的数
  1. #=
  2. julia解欧拉计划005-求最小同时都能被1-20整除的数
  3. https://projecteuler.net/problem=5
  4. =#
  5. function ff1()
  6. #= -_-!! 无脑暴力
  7. 以下表达式使用这样一行python生成然后复制粘贴过来的:
  8. '&&'.join(["x%"+str(r)+"==0" for r in range(2,21)])
  9. =#
  10. f(x)=x%2==0&&x%3==0&&x%4==0&&x%5==0&&x%6==0&&x%7==0&&x%8==0&&x%9==0&&x%10==0&&x%11==0&&x%12==0&&x%13==0&&x%14==0&&x%15==0&&x%16==0&&x%17==0&&x%18==0&&x%19==0&&x%20==0;
  11.     for r in countfrom(2)
  12.         if f(r)
  13.             println(r)
  14.         break
  15.         end
  16.     end
  17. end
  18. @time ff1()
  19. #=
  20. 232792560
  21.   5.726657 seconds (232.85 M allocations: 3.472 GB, 2.59% gc time)
  22. [Finished in 9.6s]
  23. =#
复制代码
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

  1. #julia 一行流
  2. @time @show (2^4*3^2)*(*(primes(4,20)...))
复制代码
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

回复 3# happy886rr


    一样的都是算最小公倍数。python也可以的。只是需要手动把质数都列出来。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

回复 3# happy886rr


   
你可以玩玩J语言http://www.jsoftware.com/download/j804/install/

还有lua之类的。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

欧拉论坛里好多人贴出J的一行流:
  1. *./>:i.20
复制代码
最短的是这样的。不明觉厉。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

  1. """
  2. python
  3. """
  4. from itertools import count
  5. def ff1():
  6.     #无脑暴力
  7.     # ' and '.join(["x%"+str(r)+"==0" for r in range(2,21)])
  8.     f=(lambda x:x%2==0 and x%3==0 and x%4==0 and x%5==0 and x%6==0 and x%7==0
  9. and x%8==0 and x%9==0 and x%10==0 and x%11==0 and x%12==0 and x%13==0
  10. and x%14==0 and x%15==0 and x%16==0 and x%17==0 and x%18==0 and x%19==0 and x%20==0)
  11.     for r in count(1):
  12.         if f(r):
  13.             print(r)
  14.             break
  15. ff1()
  16. """
  17. 232792560
  18. [Finished in 76.5s]
  19. """
复制代码
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

回复 8# CrLf


    J语言
http://www.jsoftware.com/
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

回复 10# happy886rr


  不要用is 判断等值。
https://segmentfault.com/q/1010000000150947
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

回复 12# happy886rr


    但是还应该用==而不是is。
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

返回列表