当前位置:网站首页>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;
}
边栏推荐
- MCU case -int0 and INT1 interrupt count
- All expansion and collapse of a-tree
- Postman核心功能解析-参数化和测试报告
- Practice: fabric user certificate revocation operation process
- IIC bus realizes client device
- The new content of the text component can be added through the tag_ Config set foreground and background colors
- EasyCVR集群部署如何解决项目中的海量视频接入与大并发需求?
- Distance from point to line intersection and included angle of line
- C language - structural basis
- Spectrum analysis of ADC sampling sequence based on stm32
猜你喜欢
The countdown to the launch of metaverse ape is hot
Double pointer of linked list (fast and slow pointer, sequential pointer, head and tail pointer)
Solutions for unexplained downtime of MySQL services
Nacos 的安装与服务的注册
Post-90s tester: "after joining Ali, this time, I decided not to change jobs."
Calculation method of boundary IOU
Promql demo service
我把开源项目alinesno-cloud-service关闭了
Spectrum analysis of ADC sampling sequence based on stm32
南京:全面启用商品房买卖电子合同
随机推荐
Practice: fabric user certificate revocation operation process
TCC of distributed solutions
Damn, window in ie open()
Binary tree (III) -- heap sort optimization, top k problem
Some tutorials install the database on ubantu so as not to occupy computer memory?
Character conversion PTA
Arduino 测量交流电流
Metaverse Ape获Negentropy Capital种子轮融资350万美元
Boring boring
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
二叉树(二)——堆的代码实现
分布式解决方案之TCC
d3dx9_ How to repair 31.dll_ d3dx9_ 31. Solution to missing DLL
FBO and RBO disappeared in webgpu
傅里叶分析概述
When the industrial Internet era is truly mature, we will look at the emergence of a series of new industrial giants
分布式解决方案选型
FBO and RBO disappeared in webgpu
Postman核心功能解析-参数化和测试报告
Metasploit (MSF) uses MS17_ 010 (eternal blue) encoding:: undefined conversionerror problem