当前位置:网站首页>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 .
边栏推荐
- Cloud development workers must go to work fishing and paddling wechat applet source code
- Library management system
- 远离才会思念
- h. 264 code stream explanation
- [untitled]
- 云开发口袋工具箱微信小程序源码
- Time for white horses to pass the gap
- ROS2/ROS1开发过程中的一些记录
- C语言:小乐乐与欧几里得
- STM32F103 learn the steps and template fool tutorial of 1-keil5 project establishment
猜你喜欢

Wechat applet - Advanced chapter Lin UI component library source code analysis button component (II)

Cloud development workers must go to work fishing and paddling wechat applet source code

Shell script quick start-01

冰冰学习笔记:运算符重载---日期类的实现

ROCBOSS开源微社区轻论坛类源码

第七天笔记

网络基础概论

自动分账系统哪家好?

FFmpeg+SDL+QT实现简单是视频播放器

云开发口袋工具箱微信小程序源码
随机推荐
HTB-Blue
践踏---离散化+树状数组+差分
Catchadmin practical tutorial (IV) implementation of relevant functions of table components
ROCBOSS开源微社区轻论坛类源码
FTP协议详解
OSPF实验
云开发打工人必备上班摸鱼划水微信小程序源码
What are the TCP retransmission mechanisms?
图书管理系统
用于校园流浪猫信息记录和分享的小程序源码/微信云开发中大猫谱小程序源码
第七天笔记
第九天笔记
Implement encapsulated public method global call in laravel framework
6 years of testing experience, teaching you how to test ~ how to control the project
Multimodal unsupervised image to image translation
架构师进阶,微服务设计与治理的 16 条常用原则
STM32F103 learn the steps and template fool tutorial of 1-keil5 project establishment
nacos名字的由来
Double write consistency of MySQL and redis
2022/07/28 learning notes (day18) common APIs