算法1:
- #include<iostream>
- using namespace std;
- int Lcm(int no1,int no2)
- {
- int temp1=no1,temp2=no2;
- int temp;
- while(no2 != 0)
- {
- temp = no2;
- no2 = no1%no2;
- no1 = temp;
- }
- temp=temp1>temp2?temp1:temp2;
- if(no1==temp)
- return temp;
- else return(temp1/no1*temp2);
- }
- int main()
- {
- int n1,n2;
- cout<<"Please cin two number,I will give least common multiple of them!"<<endl;
- cout<<"Plese the NO1:";
- cin>>n1;
- cout<<"Plese the NO2:";
- cin>>n2;
- cout<<"The least common multiple of "<<n1<<" and "<<n2<<" is "<<Lcm(n1,n2)<<endl;
- return 0;
- }
算法2:有点懒,所以文字叙述了,^_^.在两个数中找出最小的数,然后++,与最大数相乘再除以最小的那个数,如果能整除,一样可以求出结果,就是时间开销比较大点,当然具体还要细化,我只说了大概步骤..