水..
主要是最大公因数要忘干净了
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<memory.h>
using namespace std;
long long shu[1200];
int ge;
void jinqu(string qq)
{
long long s=0;
int w=0;
for(int a=qq.size()-1;a>=0;a--)
{
w++;
s=s+(qq[a]-'0')*pow(10.0,double(w));
}
shu[ge]=s;
shu[ge]=shu[ge]/10;
ge++;
}
int divisor (int a,int b)
{
int temp;
while(b!=0)
{
temp=a%b;
a=b;
b=temp;
}
return a;
}
int main()
{
int a,b;
while(cin>>a>>b)
{
cout<<a*b/divisor(a,b)<<endl;;
}
return 0;
}

本文介绍了一个简单的C++程序来计算两个整数的最大公因数(GCD)并演示了如何利用该结果来简化乘法运算。通过迭代除法的方式实现最大公因数算法,并在主函数中实现了读取输入并输出简化后的乘法结果。
1万+

被折叠的 条评论
为什么被折叠?



