1 条题解

  • 0
    @ 2025-4-7 21:29:25

    C :

    #include<stdio.h>
    int main()
    {
    	int a,b,max,min,c,d,temp,t;
    	scanf("%d%d",&a,&b);
    	c=a,d=b;
    	for(;;)
    	{
    		if(a<b)
    			temp=a,a=b,b=temp;
    		if(a%b==0)
    		{
    			max=b;
    			break;
    		}
    		else
    		t=a%b,a=b,b=t;
    	}
    	min=(c*d)/max;
    	printf("%d %d\n",max,min);
    	return 0;
    }
    

    C++ :

    #include<iostream>
    #include<fstream>
    #include<string>
    #include<cstring>
    #include<cmath>
    using namespace std;
    int  gcd(int x,int y)
    {
    	int temp;
    	if(x<y)  {temp=x;x=y;y=temp;}
    	if(y==0) return x;
    	gcd(y,x%y);
    }
    int go(int n,int m)
    {
    	return (n/gcd(m,n)*m);
    }
    int main()
    {
    	//ifstream cin("aaa.txt");
    	int i,j,n,m;
    	cin>>n>>m;
    	cout<<gcd(n,m)<<" "<<go(n,m)<<endl;
    
    
    return 0;
    }
    	
    

    Pascal :

    var
      n,m:longint;
    function gcd(a,b:longint):longint;
    var r:longint;
    begin
      r:=a mod b;
      r:=a mod b;
      while r<>0 do
      begin
        a:=b;
        b:=r;
        r:=a mod b;
      end;
      gcd:=b;
    end;
    begin
      readln(n,m);
      writeln(gcd(n,m),' ',n*m div gcd(n,m));
    end.
    
    • 1

    信息

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