当前位置:网站首页>C language: Little Lele and Euclid
C language: Little Lele and Euclid
2022-07-29 02:47:00 【Gao You Wu Shao】
Topic link
Xiao Lele recently learned in class how to find the maximum common divisor and minimum common multiple of two positive integers , But he can't find the sum of the maximum common divisor and the minimum common multiple of two positive integers , Please help him solve the problem .
#include<stdio.h>
int main()
{
long long n=0;
long long m=0;
scanf("%d %d",&n,&m);
long long t1=n;
long long t2=m;
while(n%m!=0)
{
long long tmp=n;
n=m;
m=tmp%m;
}
// Finish walking above while Got m Is the greatest common divisor
printf("%lld",m+t1*t2/m);
// Print here with lld In the form of printing , Otherwise, plastic printing will still overflow
}

Here we use the rolling division method to obtain the maximum common divisor
Minimum common multiple = primary m* primary n/ greatest common divisor , This proof is in another article of mine ,
Given the greatest common divisor, quickly find the least common multiple ( Attached certificate )
It should be noted that , The range of numbers here is [1,2^20], When calculating the least common multiple , Because of the original m* primary n So it will be very big , Do you use int It's bound to overflow , To prevent spillage , Here we simply use long long that will do .
边栏推荐
- nacos名字的由来
- etcd实现大规模服务治理应用实战
- Polygon zkEVM——Hermez 2.0简介
- 这个博主,qt归类比较全,有空去学习总结,记录一下。
- Shell script quick start-01
- Cloud development pocket toolbox wechat applet source code
- 用于校园流浪猫信息记录和分享的小程序源码/微信云开发中大猫谱小程序源码
- CUDA details GPU architecture
- Understand the evolution of redis architecture in one article
- Wechat applet - Advanced chapter Lin UI component library source code analysis button component (II)
猜你喜欢
随机推荐
How to migrate thinkphp5 projects to Alibaba cloud function computing to cope with traffic peaks?
HTB-Blue
【报错】node:internal/modules/cjs/loader:936 【解决方法】
K210 - sound source location and sound recognition
第六天笔记
Kbxxxxx is not necessarily a patch, but also a description of a solution to a problem
QT屏幕自适应自动布局,拖动窗口自动变大变小(一)
In depth analysis - Pretreatment
Shell 脚本 快速入门 -01
owt-server源码剖析(四)--video模块分析之Mixer Out
OSPF实验
0728~ sorting out interview questions
Wechat applet - Advanced chapter Lin UI component library source code analysis button component (II)
并发模式之生产者消费者模式
PHP幸运抽奖系统带后台源码
Code implementation - the greatest common factor of polynomials (linear algebra)
[error reporting] node:internal/modules/cjs/loader:936 [solution]
Cuda-npp image and video processing
C语言:判断字母
这个博主,qt归类比较全,有空去学习总结,记录一下。









