結果
| 問題 | No.14 最小公倍数ソート |
| コンテスト | |
| ユーザー |
kou6839
|
| 提出日時 | 2014-11-15 21:24:53 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 4,358 ms / 5,000 ms |
| コード長 | 1,044 bytes |
| 記録 | |
| コンパイル時間 | 2,158 ms |
| コンパイル使用メモリ | 84,572 KB |
| 実行使用メモリ | 55,892 KB |
| 最終ジャッジ日時 | 2026-06-05 09:18:53 |
| 合計ジャッジ時間 | 60,156 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 |
ソースコード
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("");
}
}
kou6839