C/C++训练1---最大公约数与最小公倍数 (sdut oj)

来源:互联网 发布:se网络验证源码 编辑:程序博客网 时间:2024/05/21 07:06


C/C++训练1---最大公约数与最小公倍数

Time Limit: 1000MS Memory Limit: 65536KB


  

Problem Description

输入两个整数,求它们的最大公约数与最小公倍数。


Input

输入两个整数,两个整数之间用空格分开。


Output

第一行输出最大公约数;
第二行输出最小公倍数。


Example Input

64 48


Example Output

16192


Hint


Author








参考代码


#include <stdio.h>int main(){    int a,b,temp,temp1,temp2;    int i=1,i2=1;    scanf("%d%d",&a,&b);    if(a > b)    {        temp = a;        a = b;        b = temp;    }    temp1 = a;    temp2 = b;    while(b % temp1)    {        temp1 = a / i;        i++;    }    while(temp2 % a)    {        temp2 = b * i2;        i2++;    }    printf("%d\n%d",temp1,temp2);    return 0;}



0 0
原创粉丝点击