当前位置:网站首页>【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法
2022-07-31 02:45:00 【rookieﻬ°】
废话不多说,直接上代码:
int main()
{
int m, n;
scanf("%d%d", &m, &n);
int mul = m * n;
int mod = m % n;
if (m == n)//解决当m==n的情况,如果m==n,那么mod==0,将造成程序浮点型错误
printf("%d\n", 2 * m);
else
{
do//辗转相除法
{
m = n;
n = mod;
mod = m % n;
} while (mod);
printf("%d\n", mul / n + n);
}
return 0;
}
【解释在标注上】
有问题请留言。
边栏推荐
- LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING
- 4. Sensitive word filtering (prefix tree)
- Brute Force/Adjacency Matrix Breadth First Directed Weighted Graph Undirected Weighted Graph
- 软件积累 -- 截图软件ScreenToGif
- Draw Your Cards
- Maximum area of solar panel od js
- print task sorting js od huawei
- AI中的数学思想
- f.grid_sample
- Clustering index, and what is the difference between a clustering index
猜你喜欢
The simulation application of common mode inductance is here, full of dry goods for everyone
7. List of private messages
Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
Static routing + PAT + static NAT (explanation + experiment)
mmdetection trains a model related command
分布式与集群是什么 ? 区别是什么?
The whole process scheduling, MySQL and Sqoop
Why is String immutable?
完整复制虚拟机原理(云计算)
Static route analysis (the longest mask matching principle + active and standby routes)
随机推荐
图解lower_bound&upper_bound
Maximum area of solar panel od js
The final exam first year course
What level of software testing does it take to get a 9K job?
LeetCode 每日一题 2022/7/25-2022/7/31
First acquaintance with C language -- array
AtCoder Beginner Contest 261 部分题解
execsnoop 工具
【CV项目调试】CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT问题
10、Redis实现点赞(Set)和获取总点赞数
mmdetection训练一个模型相关命令
LeetCode Daily Question 2022/7/25-2022/7/31
如何搭建私有yum源
多线程下类对象的服务承诺探讨
LeetCode 1161 最大层内元素和[BFS 二叉树] HERODING的LeetCode之路
Layer 2 broadcast storm (cause + judgment + solution)
12 磁盘相关命令
拒绝加班,程序员开发的效率工具集
AtCoder Beginner Contest 261 Partial Solution
Problems that need to be solved by the tcp framework