题目:

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?

此题就是求最小公倍数的,刚开始我考虑的太复杂,打算求出每个数的素数因子,然后去处一些共有的部分,后来突然想到了最小公倍数。

 1 #include<iostream>
2 using namespace std;
3 int getLeastCommonMultiple(int num1, int num2);
4 int GetMaxCommonDivide(int num1, int num2);
5 int main()
6 {
7 int res = 20;
8 for(int i = 19; i >=2; i--) {
9 if( res % i == 0){
10 continue;
11 }
12 else {
13 res = getLeastCommonMultiple(res, i);
14 }
15 }
16 cout << res << endl;
17 system("pause");
18 return 0;
19 }
20 //求最小公倍数
21 int getLeastCommonMultiple(int num1, int num2) {
22 return num1*num2/(GetMaxCommonDivide( num1, num2));
23 }
24 /* 辗转相除法求最大公约数 */
25 int GetMaxCommonDivide(int num1, int num2) {
26 int temp;
27 while(num2!=0){
28 temp = num1%num2;
29 num1 = num2;
30 num2 = temp;
31 }
32 return num1;
33 }

ProjectEuler 005题的更多相关文章

  1. ProjectEuler 做题记录

    退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧)~~当然现在高三也不怎么能上网. 2017/8/11  595 :第一题QAQ 2017/8/1 ...

  2. ProjectEuler 009题

    题目: A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For exam ...

  3. ProjectEuler 008题

    题目: The four adjacent digits in the 1000-digit number that have the greatest product are 9 9 8 9 = 5 ...

  4. ProjectEuler 007题

    题目:By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is ...

  5. ProjectEuler 006题

    题目: The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square ...

  6. ProjectEuler 004题

    1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 bool isPalindromic (int num); 6 ...

  7. ProjectEuler 003题

    1 //题目:The prime factors of 13195 are 5, 7, 13 and 29. 2 //What is the largest prime factor of the n ...

  8. nim也玩一行流,nim版的list comprehension

    nim 是一门风格类似python的静态编译型语言,官方网站:http://nim-lang.org 如果你想折腾nim的编辑环境,可以用sublime text3 +插件nimlime,notepa ...

  9. ProjectEuler && Rosecode && Mathmash做题记录

    退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧) 2017/8/11  PE595 :第一题QAQ 2017/8/12  PE598 2017/ ...

随机推荐

  1. MapReduce学习总结之简介

    执行步骤:1)准备Map处理的输入数据 2)Mapper处理 3)Shuffle 4)Reduce处理 5)结果输出 三.mapreduce核心概念: 1)split:交由MapReduce作业来处理 ...

  2. if函数+isna函数+vlookup函数实现不同列相同单元格内容排列在同一行

    1,首先学习的网址:https://jingyan.baidu.com/album/22a299b5dd0f959e19376a22.html?picindex=1 2,excel 这也许是史上最好最 ...

  3. deepin修改数据源升级到deepin15.11桌面版

    参考:https://blog.csdn.net/baidu_41751590/article/details/89064220 1,我修改数据源地址: 换成上海交通大学源地址: http://ftp ...

  4. 【Mysql】一个简易的索引方案

    一.没有索引的时候如何查找 先忽略掉索引这个概念,如果现在直接要查某条记录,要如何查找呢? 在一个页中查找 如果表中的记录很少,一个页就够放,那么这时候有 2 种情况: 用主键为搜索条件:这时就是之前 ...

  5. Linux 安装 Nodejs 的两种方式

    Linux 安装 Nodejs 的两种方式 目录 Linux 安装 Nodejs 的两种方式 一.压缩包安装 Nodejs 二.源码编译安装 Nodejs 一.压缩包安装 Nodejs 下载 Node ...

  6. 使用Elastic Job的分片配置加速任务执行和提高资源利用率

    上一篇,我们介绍了如何使用Elastic Job实现定时任务.解决了使用@Scheduled来实现时候存在的竞争问题,同时也实现了定时任务的高可用执行. 然而,还有一类问题是我们在做定时任务时候容易出 ...

  7. (java4)什么是计算机

    (java4)什么是计算机 computer : 全称电子计算机,俗称电脑 能够按照程序运行.自动.高速处理海量数据的现代化智能电子设备 由硬件和软件组成 常见的由台式计算机,笔记本计算机,大型计算机 ...

  8. 深入刨析tomcat 之---第8篇 how tomcat works 第11章 11.9应用程序,自定义Filter,及注册

    writed by 张艳涛, 标签:全网独一份, 自定义一个Filter 起因:在学习深入刨析tomcat的学习中,第11章,说了调用过滤链的原理,但没有给出实例来,自己经过分析,给出来了一个Filt ...

  9. jvm源码解读--11 ldc指令的解读

    写一个java文件 public static void main(String[] args) { String str1="abc"; String str2 ="a ...

  10. memcache(11211)未授权访问

    1.安装Memcache服务端 sudo apt-get install memcached 2.启动服务 sudo memcached -d -m 128 -p 11211 -u root 3.ap ...