当前位置:网站首页>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. !

边栏推荐
- Hcip - OSPF comprehensive experiment
- 基于C语言的LR1编译器设计
- A Keypoint-based Global Association Network for Lane Detection
- 达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人
- 认知篇----硬件工程师的成才之路之经典
- Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers
- Leetcode Tencent selected exercises 50 questions -059. Spiral matrix II
- 在“元宇宙空间”UTONMOS将打开虚实结合的数字世界
- 【idea】设置提取serialVersionUID
- 文旅数藏 | 用艺术的方式游云南
猜你喜欢

A Keypoint-based Global Association Network for Lane Detection

A Keypoint-based Global Association Network for Lane Detection
idea Gradle7.0+ :Could not find method compile()

Hcip - OSPF comprehensive experiment

Dako held a meeting for the biological IPO: the annual revenue was 837million, and Wu Qingjun and his daughter were the actual controllers

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

Cognition -- classic of the road to success of hardware engineers

Design of LR1 compiler based on C language

【笔记】逻辑斯蒂回归

Wechat campus laundry applet graduation design finished product (5) assignment
随机推荐
小程序毕设作品之微信校园洗衣小程序毕业设计成品(1)开发概要
windows10 安装Sql Server 2019
Vscode -- create template file
知识关联视角下金融证券知识图谱构建与相关股票发现
Motion attitude control system of DOF pan tilt based on stm32
达科为生物IPO过会:年营收8.37亿 吴庆军父女为实控人
利用C语言实现URL解析的基本方法之优秀
[luogu_p4556] [Vani has an appointment] tail in rainy days / [template] segment tree merging
WPF visifire.charts4.6.1 tutorial with source code
We should learn to check the documented instructions of technical details
A Keypoint-based Global Association Network for Lane Detection
JWT login expiration - automatic refresh token scheme introduction
Realize the basic operations such as the establishment, insertion, deletion and search of linear tables based on C language
The most complete collection of strategies! Super AI painting tool midjourney open beta! Come and build your fantasy metauniverse
面向不平衡数据的电子病历自动分类研究
纯c手写线程池
How to test and decrypt the encryption interface
Wechat campus laundry applet graduation design finished product of applet completion work (8) graduation design thesis template
小程序毕设作品之微信校园洗衣小程序毕业设计成品(5)任务书
阻塞队列BlockingQueue