解题思路:辗转相除法
注意事项:m,n需保留原值
参考代码:
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
using namespace std;
int main(){
int m,n,greatest_common_divisor,Least_common_multiple,num,Originally_m,Originally_n;
cin>>m>>n;
Originally_m=m;
Originally_n=n;
while(m%n){
num=m%n;
m=n;
n=num;
}
greatest_common_divisor=n;
Least_common_multiple=(Originally_n*Originally_m/greatest_common_divisor);
cout<<greatest_common_divisor<<" "<<Least_common_multiple;
return 0;
}
0.0分
3 人评分
A+B for Input-Output Practice (IV) (C语言代码)浏览:484 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:699 |
1012题解浏览:938 |
字符串输入输出函数 (C语言代码)浏览:2604 |
模拟计算器 (C++代码)浏览:885 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:724 |
用筛法求之N内的素数。 (C语言代码)浏览:595 |
钟神赛车 (C语言代码)浏览:665 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:501 |
C语言程序设计教程(第三版)课后习题6.8 (C语言代码)浏览:683 |