結果

問題 No.14 最小公倍数ソート
ユーザー kou6839
提出日時 2014-11-15 21:24:53
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 1,044 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 79,796 KB
実行使用メモリ 128,032 KB
最終ジャッジ日時 2024-12-31 20:29:51
合計ジャッジ時間 86,830 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 TLE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
 
class Pare implements Comparable<Pare>{
	int moto;
	int lcm;
	Pare(int moto,int lcm){
		this.moto=moto;
		this.lcm=lcm;
	}
	@Override
	public int compareTo(Pare o) {
		int res = this.lcm-o.lcm;
		if(res==0) return this.moto-o.moto;
		return res;
	}
	
}
public class Main {
	static int gcd(int a,int b){
		if(a>b){
			int temp;
			temp=a;
			a=b;
			b=temp;
		}
		while(a != 0){
			int temp=a;
			a = b%a;
			b=temp;
		}
		return b;
	}
	static int lcm(int a,int b){
		return (a*b)/gcd(a,b);
	}
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Pare[] a = new Pare[n];
    for(int i=0;i<n;i++){
    	int temp=sc.nextInt();
    	a[i]=new Pare(temp,temp);
    }
    for(int i=0;i<=n-3;i++){
    	for(int j=i+1;j<n;j++){
    		a[j].lcm=lcm(a[i].moto,a[j].moto);
    	}
    	Arrays.sort(a,i+1,n);
    }
    for(Pare f :a){
    	System.out.print(f.moto+" ");
    }
    System.out.println("");
    

    }
} 
0