题目:

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. 备战- Java虚拟机

    备战- Java虚拟机 试问岭南应不好,却道,此心安处是吾乡. 简介:备战- Java虚拟机 一.运行时数据区域 程序计算器.Java 虚拟机栈.本地方法栈.堆.方法区 在Java 运行环境参考链接: ...

  2. CentOS更换网易yum源

    最新内容和地址参见http://mirrors.163.com/.help/centos.html 1 首先备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yu ...

  3. 【洛谷P1795 无穷的序列_NOI导刊2010提高(05)】模拟

    分析 map搞一下 AC代码 #include <bits/stdc++.h> using namespace std; map<int,int> mp; inline int ...

  4. 数据分析学习1-----matplotlib

    安装:Anaconda 详细见:https://blog.csdn.net/lwplwf/article/details/79162470 使用^ThinkPad-E560:~# spyder  命令 ...

  5. 解决proto文件转换时提示“Note that enum values use C++ scoping rules, meaning that enum values are siblings of their type, not children of it. ”

    前言: 想将.proto文件转换成.pb文件时一直报错,一开始以为是文件编码格式的问题,后来将文件改成windows下的utf-8格式后,又出现了新的报错(见下图).百度了很久,才找到解决方法. &q ...

  6. 构建后端第3篇之---springb @Alias注解使用

    write by 张艳涛 in 202210210,after today i will  write aritles by english,because english is so diffent ...

  7. Spring Data Commons 远程命令执行漏洞(CVE-2018-1273)

    影响版本 Spring Framework 5.0 to 5.0.4 Spring Framework 4.3 to 4.3.14 poc https://github.com/zhzyker/exp ...

  8. DC-8靶机

    仅供个人娱乐 靶机信息 下载地址:http://www.five86.com/downloads/DC-8.zip 一.主机扫描 二.信息收集 http://192.168.17.135/robots ...

  9. [ZJOI2010]基站选址,线段树优化DP

    G. base 基站选址 内存限制:128 MiB 时间限制:2000 ms 标准输入输出 题目类型:传统 评测方式:文本比较   题目描述 有N个村庄坐落在一条直线上,第i(i>1)个村庄距离 ...

  10. Mongodb集成LDAP授权

    一.环境简介 Mongodb enterprise v4.0.16 OpenLDAP v2.4.44 二.Mongodb集成LDAP的授权过程 客户端指定某种外部验证方式链接Mongodb: Mong ...