当前位置:网站首页>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;
}
边栏推荐
- 记录几个常见问题(202207)
- 请求二进制数据和base64格式数据的预览显示
- [secretly kill little buddy pytorch20 days] - [Day2] - [example of picture data modeling process]
- QT creator 7-cmake update
- Lesson 1: serpentine matrix
- Damn, window in ie open()
- How to quickly experience oneos
- How to reverse a string fromCharCode? - How to reverse String. fromCharCode?
- 700. Search in a Binary Search Tree. Sol
- 基于STM32的ADC采样序列频谱分析
猜你喜欢
Vcomp110.dll download -vcomp110 What if DLL is lost
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
从 1.5 开始搭建一个微服务框架——日志追踪 traceId
航海日答题小程序之航海知识竞赛初赛
点到直线的距离直线的交点及夹角
Navigation day answer applet: preliminary competition of navigation knowledge competition
Google Maps case
Golang writes the opening chapter of selenium framework
2022 Software Test Engineer salary increase strategy, how to reach 30K in three years
[untitled]
随机推荐
Distributed resource management and task scheduling framework yarn
[agc009e] eternal average - conclusion, DP
Starting from 1.5, build a micro Service Framework -- log tracking traceid
First, redis summarizes the installation types
关于MySQL的30条优化技巧,超实用
Understand the basic concept of datastore in Android kotlin and why SharedPreferences should be stopped in Android
Golang writes the opening chapter of selenium framework
Some tutorials install the database on ubantu so as not to occupy computer memory?
How to quickly experience oneos
Opencv judgment points are inside and outside the polygon
Hcip day 16
Go language learning tutorial (XV)
Character conversion PTA
链表之双指针(快慢指针,先后指针,首尾指针)
Boring boring
The countdown to the launch of metaverse ape is hot
南京:全面启用商品房买卖电子合同
记录几个常见问题(202207)
The code generator has deoptimised the styling of xx/typescript. js as it exceeds the max of 500kb
[groovy] mop meta object protocol and meta programming (Introduction to groovyobject interface | introduction to metaclass | implementation of class methods using groovyobject invokemethod)