ProjectEuler 005题
题目:
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题的更多相关文章
- ProjectEuler 做题记录
退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧)~~当然现在高三也不怎么能上网. 2017/8/11 595 :第一题QAQ 2017/8/1 ...
- ProjectEuler 009题
题目: A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For exam ...
- ProjectEuler 008题
题目: The four adjacent digits in the 1000-digit number that have the greatest product are 9 9 8 9 = 5 ...
- ProjectEuler 007题
题目:By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is ...
- ProjectEuler 006题
题目: The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square ...
- ProjectEuler 004题
1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 bool isPalindromic (int num); 6 ...
- ProjectEuler 003题
1 //题目:The prime factors of 13195 are 5, 7, 13 and 29. 2 //What is the largest prime factor of the n ...
- nim也玩一行流,nim版的list comprehension
nim 是一门风格类似python的静态编译型语言,官方网站:http://nim-lang.org 如果你想折腾nim的编辑环境,可以用sublime text3 +插件nimlime,notepa ...
- ProjectEuler && Rosecode && Mathmash做题记录
退役选手打发时间的PE计划 挂在这里主要是dalao们看到有什么想交流的东西可以私聊哦(站内信或邮箱吧) 2017/8/11 PE595 :第一题QAQ 2017/8/12 PE598 2017/ ...
随机推荐
- vue如何动态加载本地图片
大家好,我是前端队长Daotin,想要获取更多前端精彩内容,关注我(全网同名),解锁前端成长新姿势. 以下正文: 今天遇到一个在vue文件中引入本地图片的问题,于是有了这篇文章. 通常,我们的一个im ...
- 如何用css画一个彩虹---v客学院技术分享
无意间看到了CSS radial-gradient() 函数实现了如下图的样式 仔细一看还真有点像灯光下的鸡蛋,O(∩_∩)O哈哈~ 今天我就来用radial-gradient()函数教大家画一个简单 ...
- request - cookie 操作(一)
from urllib import request#headers 带cookieblog_url = "http://www.renren.com/452057374/profile?r ...
- odoo里面批量上传图片
import os import base64 def base_data_product_image(self): """ odoo里批量创建产品,并上传图片 图片为b ...
- upload-lab 靶场实战
文件上传/下载 漏洞 冲冲冲,好好学习 2020.02.13 淦靶场之前,先来点知识铺垫铺垫. 文件上传漏洞 前端Js绕过. MIME类型绕过 后缀名大写写绕过 / php4 .php5 00截断 覆 ...
- 打开JAVA之门:idea的安装及JAVA环境的创建
打开JAVA之门:idea的安装及JAVA环境的创建 1.idea的下载安装 首先打开 ->->->(IntelliJ IDEA: The Capable & Ergonom ...
- JAVA虚拟机的组成>从零开始学java系列
目录 JAVA虚拟机的组成 什么是虚拟机? JAVA虚拟机的组成部分 堆区(堆内存) 方法区 虚拟机栈 本地方法栈 程序计数器 字符串常量池 JAVA虚拟机的组成 什么是虚拟机? 虚拟机是运行在隔离环 ...
- 学废了系列 - WebGL与Node.js中的Buffer
WebGL 和 Node.js 中都有 Buffer 的使用,简单对比记录一下两个完全不相干的领域中 Buffer 异同,加强记忆. Buffer 是用来存储二进制数据的「缓冲区」,其本身的定义和用途 ...
- Vulhub-DC-3靶场
Vulhub-DC-3靶场 前言 今天把DC-3的靶场打了一遍,可以说这个靶场用到的思路是非常经典的,从信息搜集到漏洞利用包括内核提权.最最重要的是为了下载它的提权EXP,我它喵还花了一块二买了个CS ...
- 如何在Spring Data MongoDB 中保存和查询动态字段
原文: https://stackoverflow.com/questions/46466562/how-to-save-and-query-dynamic-fields-in-spring-data ...