当前位置:网站首页>3 find the greatest common divisor and the least common multiple
3 find the greatest common divisor and the least common multiple
2022-07-05 22:43:00 【buyizhu021】
Title Description
Enter two integers , Find the greatest common divisor and the least common multiple of two integers , And output the result .
Let two integers be u and v, The algorithm for finding the greatest common divisor and the least common multiple by rolling division is as follows :
if v>u
Put the variable u And v In exchange for ( Make the big one u For divisor )
while (u/v The remainder of r!=0)
{u=v ( Divisor v Become a divisor u)
v=r ( Make the remainder r Become a divisor v)
}
Output the greatest common divisor v( at present )
Minimum common multiple l=u*v( original )/ greatest common divisor v
The sample input
36 12
Sample output
greatest common divisor :12
Minimum common multiple :36
Code
#include <iostream>
using namespace std;
int max(int m,int n)
{int t,r,max;
if(n>m)
{t=n;n=m;m=t;}
r=m%n;
while(r!=0)
{m=n;n=r;r=m%n;}
max=n;
return max;
}
int min(int m,int n,int c)
{int min;
min=m*n/c;
return min;
}
int main()
{ int m,n,x,y;
cin>>m>>n;
x=max(m,n);
y=min(m,n,x);
cout<<" greatest common divisor :"<<x<<endl;
cout<<" Minimum common multiple :"<<y<<endl;
return 0;
}
边栏推荐
- Function default parameters, function placeholder parameters, function overloading and precautions
- Global and Chinese markets for reciprocating seal compressors 2022-2028: Research Report on technology, participants, trends, market size and share
- 航海日答题小程序之航海知识竞赛初赛
- Request preview display of binary data and Base64 format data
- 分布式解决方案之TCC
- Oracle is sorted by creation time. If the creation time is empty, the record is placed last
- Overview of Fourier analysis
- Shelved in TortoiseSVN- Shelve in TortoiseSVN?
- [Chongqing Guangdong education] National Open University autumn 2018 0088-21t Insurance Introduction reference questions
- What about data leakage? " Watson k'7 moves to eliminate security threats
猜你喜欢
链表之双指针(快慢指针,先后指针,首尾指针)
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
MCU case -int0 and INT1 interrupt count
Paddle Serving v0.9.0 重磅发布多机多卡分布式推理框架
Postman core function analysis - parameterization and test report
Kubernetes Administrator certification (CKA) exam notes (IV)
700. Search in a Binary Search Tree. Sol
Exponential weighted average and its deviation elimination
Metaverse ape ape community was invited to attend the 2022 Guangdong Hong Kong Macao Great Bay metauniverse and Web3.0 theme summit to share the evolution of ape community civilization from technology
Solutions for unexplained downtime of MySQL services
随机推荐
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
Tiktok__ ac_ signature
Hcip day 16
[error record] file search strategy in groovy project (src/main/groovy/script.groovy needs to be used in the main function | groovy script directly uses the relative path of code)
The introduction to go language is very simple: String
What about data leakage? " Watson k'7 moves to eliminate security threats
The difference between MVVM and MVC
Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
Platform bus
Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space
audiopolicy
实战:fabric 用户证书吊销操作流程
Vcomp110.dll download -vcomp110 What if DLL is lost
Evolution of APK reinforcement technology, APK reinforcement technology and shortcomings
Some tutorials install the database on ubantu so as not to occupy computer memory?
I closed the open source project alinesno cloud service
Distributed solution selection
Metaverse Ape上线倒计时,推荐活动火爆进行
opencv 判断点在多边形内外
New 3D particle function in QT 6.3