a questions
2015-06-09 10:13
417 查看
1.2520 is the smallest nuber that can be diveded by each of the number 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?
Use ruby to solve this problem
....
(1..20).to_a.reduce :lcm
what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Use ruby to solve this problem
b=Array.new c = gets.chomp a = 1..c.to_i jc=1 a.each do |elem| b<<elem.to_i end b.each do |e| jc *= e end x=b.max sum=1 co = 1*x x.upto(jc) do |i| sum=0 b.each do |f| sum += (i%f) end if sum == 0 co=i break end end puts "The common multiple is #{co}"
....
(1..20).to_a.reduce :lcm
相关文章推荐
- UIImage 切图
- jsp中 response和request区别
- 【Java GUI】文本框和文本区
- Android Studio --> Gradle Build设置自动
- Adeneo Embedded: Building Qt 5.1 for Freescale i.MX6Introduction on LTIB
- Building QT5 for IMX6(all)
- hdu 4027 Can you answer these queries?(线段树)
- UILabel调整字间距
- UITextView的创建/背景图片/边框和颜色/圆角等
- 关于在openstack中创建实例时任务一直卡在Building的现象描述
- Java GUI 使用确认对话框控制循环
- Column count doesn't match value count at row 1解决方法
- Atitit.guice3 ioc 最佳实践 o9o
- longest-common-subsequence
- pytest框架系列教程:pytest框架在UI自动化测试中的应用
- Android之UI主线程更新问题
- 如何在Sublime Text中创建build system命令打开浏览器预览html页面
- UIButton 设置圆角 边框颜色 点击回调方法
- UIScrollView常见属性
- java基础—GUI概述