当前位置:网站首页>Recursive method to realize the greatest common divisor
Recursive method to realize the greatest common divisor
2022-07-27 14:06:00 【Taro paste】
| greatest common divisor |
The greatest common factor , Also known as the greatest common divisor 、 The greatest common factor , Refers to the common divisor of two or more integers Maximum One of the
There are many ways to find the greatest common divisor : The prime factor decomposition method 、 Short division 、 division 、 More derogation etc.
Next, we take the rolling division method as an example to find the maximum common divisor of two numbers
division
division : Division by rotation is a method of finding the greatest common divisor of two natural numbers , It's also called Euclidean algorithm .
for example :
seek (319,377):
∵ 319÷377=0( more than 319)
∴(319,377)=(377,319);
∵ 377÷319=1( more than 58)
∴(377,319)=(319,58);
∵ 319÷58=5( more than 29)
∴ (319,58)=(58,29);
∵ 58÷29=2( more than 0)
∴ (58,29)= 29;
∴ (319,377)=29.
To find the greatest common divisor of several numbers by means of division , You can find out one first Any two numbers Of greatest common divisor , Then find the greatest common divisor and The third number Maximum common divisor of , Go on in turn , Until the last number . The greatest common divisor of the final result , It's the greatest common divisor of all these numbers .
| Data analysis |
As mentioned above , You can use rolling division ( Euclidean algorithm ) To find the greatest common divisor , Then we can 319,377 these two items. Specific values use The parameters of the function Come on Instead of . Next, look for his rules
The first round
take (319,377) See as (a,b);
that
319÷377=0( more than 319) It can be seen as a%b=x ( more than n);
- n For the remainder
(319,377)=(377,319); Be similar to (a,b)= (b,n);
( namely b=377,n=319)
- Be careful : second 319 Not at first a=319 Number of numbers , It is a%b Remainder obtained
The second round
377÷319=1( more than 58) Can be seen as a=377,b=319,a%b=x( more than n);
(377,319)=(319,58); Be similar to (a,b)= (b,n);
Compared with the previous round , We can Last round b,n The value of is assigned to the second round a,b, Until the remainder is 0 when ,b For the greatest common divisor ,
Here we can use recursive method to realize 
| Completion code |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script> // division function measure(a, b) {
var n = a % b // Take the remainder if (n == 0) {
// Determine whether the remainder is 0, by 0 Output b For the greatest common divisor return b; } else {
a = b; // The last round of b The value of a b = n; // The last round of n The value of b return measure(a, b); // recursive Continue to call the function until the remainder n by 0 } } console.log(measure(319, 377));;// 29 </script>
</body>
</html>
Good luck is hidden in effort ~ come on. !

边栏推荐
- Flat die cutting machine
- 592. Fraction addition and subtraction
- 小程序毕设作品之微信校园洗衣小程序毕业设计成品(6)开题答辩PPT
- RSS tutorial: aggregate your own information collection channels, rshub, freshrss, NetNewsWire
- Good architecture is evolved, not designed
- CARLA 笔记(04)— Client 和 World (创建 Client、连接 World 、批处理对象、设置 Weather、设置 Lights、World snapshots)
- 小程序毕设作品之微信校园洗衣小程序毕业设计成品(4)开题报告
- Thinkphp+ pagoda operation environment realizes scheduled tasks
- Onnxruntime [reasoning framework, which users can easily use to run an onnx model]
- 【图论】负环
猜你喜欢

Wechat campus laundry applet graduation design finished product of applet completion work (8) graduation design thesis template

Flat die cutting machine

小程序毕设作品之微信校园洗衣小程序毕业设计成品(6)开题答辩PPT
![[internship experience] add your own implementation method to the date tool class](/img/56/54c5f62438a627c96f8b4ad06ba863.jpg)
[internship experience] add your own implementation method to the date tool class

达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人

面向流行性疾病科普的用户问题理解与答案内容组织

深度置信网络(DBN)【经典的DBN网络结构是由若干层 RBM(受限波尔兹曼机)和一层 BP 组成的一种深层神经网络】

小程序毕设作品之微信校园洗衣小程序毕业设计成品(1)开发概要

YOLOX改进之一:添加CBAM、SE、ECA注意力机制

Zhishang technology IPO meeting: annual revenue of 600million, book value of accounts receivable of 270Million
随机推荐
Keras deep learning practice - recommend system data coding
用命令如何返回上级目录
idea Gradle7.0+ :Could not find method compile()
Leetcode Tencent selected exercises 50 questions -059. Spiral matrix II
A Keypoint-based Global Association Network for Lane Detection
Cognition -- classic of the road to success of hardware engineers
There is no need for semantic segmentation of annotation data! Eth & Leuven University proposed maskdistill, using transformer for unsupervised semantic segmentation, SOTA
MySQL startup options and configuration files
基于RoBERTa-wwm动态融合模型的中文电子病历命名实体识别
Converter registration of easyexcel
List map basic notes
Application layer World Wide Web WWW
Small program completion work wechat campus laundry small program graduation design finished product (2) small program function
The most complete collection of strategies! Super AI painting tool midjourney open beta! Come and build your fantasy metauniverse
PCL 常用操作
redis集群搭建-使用docker快速搭建一个测试redis集群
LeetCode·每日一题·592.分数加减运算·模拟
[training day3] section [greed] [two points]
基于C语言实现线性表的建立、插入、删除、查找等基本操作
A Keypoint-based Global Association Network for Lane Detection