1 条题解

  • 0
    @ 2025-4-12 21:36:06

    C :

    #include<stdio.h>
    main()
    {
     int a,b,num1,num2,temp;
     
     while(scanf("%d %d",&num1,&num2)!=EOF)
     {
     
     if(num1<num2)  
     { temp=num1;
      num1=num2; 
      num2=temp;
     }
    a=num1;b=num2;
    while(b!=0)/*利用辗除法,直到b为0为止*/
     {
      temp=a%b;
      a=b;
      b=temp;
     }
     printf("%d",num1*num2/a);
    printf(" %d",a);
    
    printf("\n");
    }
    }
    

    C++ :

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cmath>
    #include <string>
    
    using namespace std;
    
    int gcd(int a, int b) {
      if (b != 0)
        return gcd(b, a % b);
      else
        return a;
    }
    
    int main() {
      //freopen("Problem8.in", "r", stdin);
      //freopen("Problem8.out", "w", stdout);
    
      int a, b;
      while (scanf("%d %d", &a, &b) != EOF) {
        int c = gcd(a, b);
        printf("%d %d\n", a * b / c, c);
      }
    
      return 0;
    }
    
    • 1

    信息

    ID
    833
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者