1 条题解

  • 0
    @ 2025-4-7 21:41:51

    C :

    #include<stdio.h>
    int gcd(int x, int y){
      if(x%y==0) return y;
      else return gcd(y, x%y);
    }
    int main(){
      int x, y, g;
      while(scanf("%d%d", &x, &y)==2){
        g=gcd(x, y);
        printf("%d\n", x*y/g);
      }
      return 0;
    }
    

    C++ :

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

    Pascal :

    var a,b,s,i:longint;
    begin
      while not eof do
        begin
          readln(a,b);
          i:=1;
          s:=a*i;
          while s mod b<>0 do
            begin
             inc(i);
             s:=a*i;
            end;
          writeln(s);
        end; 
    end.
    
    

    Java :

    import java.util.Scanner;
    
    /**
     * Created with IntelliJ IDEA.
     * User: Worshiper
     * Date: 13-10-28
     * Time: 下午10:52
     */
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            while (in.hasNext()) {
                int a = in.nextInt();
                int b = in.nextInt();
                System.out.println(a * b / solve(a, b));
            }
        }
    
        private static int solve(int i, int j) {
            if (j == 0)
                return i;
            return solve(j, i % j);
        }
    }
    
    
    • 1

    信息

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