当前位置:网站首页>greatest common divisor
greatest common divisor
2022-07-24 04:37:00 【Hi hi】
List of articles
【C Language – The road of big men 】
List of articles
1. What is a common divisor ?
Common divisor , Also known as “ The common factor ”. It is a number that can divide several integers at the same time . If an integer is several integers at the same time Divisor , Call this integer their “ Common divisor ”.
2. greatest common divisor
The largest of the common divisors is called the greatest common divisor . For any number of positive integers ,1 Their common factor is always . The common divisor is opposite to the common multiple , Is both A The divisor of is also B The divisor of ,12 and 15 The common divisor of is 1,3, The greatest common divisor is 3. Another example ,30 and 40, Their common divisors are 1,2,5,10, The greatest common divisor is 10
3. The relationship between the greatest common divisor and the least common multiple :
The product of two numbers / greatest common divisor = Minimum common multiple
4. Problem solving guidance
Such as 18 and 6, We can know that the greatest common divisor of two numbers must be less than or equal to the smallest one , Then to achieve the greatest common divisor , You must first find the smallest of the two numbers
And then from 6 Or ratio 6 Find the least common divisor among small numbers

5. Code display :
The code is as follows ( Example ):
#include<stdio.h>
int main() {
int m = 0;
int n = 0;
scanf("%d %d", &m, &n);
int min = (m < n ? m : n);
while (1)
{
if (m % min == 0 && n % min == 0)
{
printf("%d", min);
break;
}
min--;
}
return 0;
}
Of course, there is more than one method , This method is inefficient
6. division
The introduction is shown in the figure :
Pictured , use 24 except 18 Take the remainder 6
use 18 except 6 Take remainder as 0
6 Is the greatest common divisor of these two numbers
As shown in the figure above, if we put 24 regard as m, hold 18 regard as n, If the remainder is not 0, will n The value is assigned to m, The value of the remainder is assigned to n
Remainder if yes 0,n Is the greatest common divisor
7. Code demonstration :
#include<stdio.h>// greatest common divisor
int main() {
int m = 0;
int n = 0;
int r = 0;
scanf("%d %d", &m, &n);
while (r = m % n)
{
m = n;
n = r;
}
printf("%d", n);
return 0;
}
summary
The contents involved here are quite basic , If you don't know some syntax in the above code , It shows that the foundation is too weak
You can read my series of articles 【C】 C Introduction to language
Of course, as long as you have a clear idea , This kind of code is still very easy to write .
边栏推荐
- Live broadcast preview | practice sharing of opengauss' autonomous operation and maintenance platform dbmind
- Why can't I hide folders? Solutions to the hidden folders on the computer that can still be seen
- -Bash: wget: command not found
- Game improvement of smart people: Lesson 2 of Chapter 3: number of factors
- 链接预测中训练集、验证集以及测试集的划分(以PyG的RandomLinkSplit为例)
- Shell syntax (1)
- Billiard simulator based on the integration of GL pipeline and ray tracing technology
- Ambire wallet opens twitter spaces series
- Qt5.14_MinGW/MSVC下实现VS2019面板自由拖拽组合功能
- Nautilus 3.19.2为Gnome增添动力
猜你喜欢

Qt5.14_ Realize the free drag and drop combination function of vs2019 panel under mingw/msvc

一次线上事故,我顿悟了异步的精髓

Common cross domain problems

Smart contract: release an erc20 token

C language classic exercises to write a program to find all the perfects within 1000.

Array force buckle (continuously updated)

Logback log framework technology in project development
【望解答】数据无法正确同步了

LabVIEW master VI freeze pending

基于C语言设计的一个医院叫号系统
随机推荐
Common cross domain problems
Er system, in Lin reply bit, count, successfully open r com change
What if IPv4 has no internet access? Solutions to IPv4 without internet access rights (detailed explanation of pictures and texts)
致-.-- -..- -
Godson leader spits bitterness: we have the world's first performance CPU, but unfortunately no one uses it!
Little black gnawing leetcode:589. Preorder traversal of n-ary tree
Particle Designer: particle effect maker, which generates plist files and can be used normally in projects
.gz的业务交互和对外服篇中我们通合多个模型
How to make yourself look young in how old robot? How old do I look? Younger method skills
Smart contract: release an erc20 token
Face algorithms
仿今日头条实时新闻微信小程序项目源码
Where is the difficulty in attracting investment in the park? Inventory of difficulties and difficulties in attracting investment in industrial parks
【ARC127F】±AB
C语言经典习题之评委打分去掉最高最低求平均分
dispatch_ Once's Secret
Alibaba Taobao Department interview question: how does redis realize inventory deduction and prevent oversold?
归并排序(Merge sort)
Little black leetcode journey: 100 same trees
LabVIEW主VI冻结挂起