1 条题解

  • 0
    @ 2025-12-5 16:55:32

    C :

    #include<stdio.h>
    void swap(int *a,int *b)
    {
       int temp;
       if(*a<*b)
       {
        temp=*a;
        *a=*b;
        *b=temp;
       }
    }
    int main()
    {
        int m,n,r;
        while(scanf("%d%d",&m,&n)!=EOF)
        {
          swap(&m,&n);
          r=m*n;
          while(m%n!=0)
          {
           m=m%n;
           swap(&m,&n);
          }
          printf("%d %d\n",n,r/n);
        }
        return 0;
    } 
    
    

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
    	int a,b,c,i;
    	cin>>a>>b;
    	if(a>b)
    	{
    		c=b;
    		b=a;
    		a=c;
    	}
    	for(i=1;i<a+1;i++)
    	{
    		if(a%i==0&&b%i==0)
    		{
    			c=i;
    		}
    	}
    	i=a*b/c;
    	cout<<c<<" "<<i;
    }
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		final int n = 100000;
    		
    		Scanner input = new Scanner(System.in);
    		
    		int x = input.nextInt();
    		int y = input.nextInt();
    		int r,x1 = x,y1 = y,m;
    		while(y != 0){
    			r = x % y;
    			x = y;
    			y = r;
    		}
    		m = x * (x1 / x) * (y1 / x);
    		System.out.println(x + " " + m);
    		input.close();
    	}
    	
    	
    
    }
    
    

    Python :

    
    a = map(lambda x:int(x), raw_input().split())
    
    def yu(a, b):
        if a < b:
            a, b = b, a
        a = a % b
        if a == 0:
            return b
        return yu(b,a)
    x = yu(a[0], a[1])
    print "%d %d" % (x, a[0] * a[1] // x)
    
    • 1

    Greatest common divisor and Minimum common multiple

    信息

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