当前位置:网站首页>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;
}边栏推荐
- Draw a red lantern with MATLAB
- 我对新中台模型的一些经验思考总结
- Exponential weighted average and its deviation elimination
- 记录几个常见问题(202207)
- Damn, window in ie open()
- Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
- 谷歌地图案例
- Three "factions" in the metauniverse
- Solutions for unexplained downtime of MySQL services
- Distance entre les points et les lignes
猜你喜欢

Nangou Gili hard Kai font TTF Download with installation tutorial

Google Maps case
![[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)](/img/b6/b2036444255b7cd42b34eaed74c5ed.jpg)
[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)

Arduino measures AC current

Nacos installation and service registration

Analysis of the problem that the cookie value in PHP contains a plus sign (+) and becomes a space

How can easycvr cluster deployment solve the massive video access and concurrency requirements in the project?

【无标题】

Kubernetes Administrator certification (CKA) exam notes (IV)

Distance from point to line intersection and included angle of line
随机推荐
航海日答题小程序之航海知识竞赛初赛
What changes has Web3 brought to the Internet?
Spectrum analysis of ADC sampling sequence based on stm32
我对新中台模型的一些经验思考总结
Post-90s tester: "after joining Ali, this time, I decided not to change jobs."
Assign the output of a command to a variable [repeat] - assigning the output of a command to a variable [duplicate]
Performance testing of software testing
Qtquick3d real time reflection
Metaverse Ape猿界应邀出席2022·粤港澳大湾区元宇宙和web3.0主题峰会,分享猿界在Web3时代从技术到应用的文明进化历程
请求二进制数据和base64格式数据的预览显示
I closed the open source project alinesno cloud service
Damn, window in ie open()
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题
509. Fibonacci Number. Sol
How to create a thread
Vcomp110.dll download -vcomp110 What if DLL is lost
Arduino measures AC current
二叉树(三)——堆排序优化、TOP K问题
Distributed solution selection
Metasploit(msf)利用ms17_010(永恒之蓝)出现Encoding::UndefinedConversionError问题