結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー pekempey
提出日時 2015-06-20 13:47:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 2,034 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 80,232 KB
実行使用メモリ 42,624 KB
最終ジャッジ日時 2024-07-07 15:12:17
合計ジャッジ時間 11,352 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;

class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);

        int[] t = new int[3];

        for (int i = 0; i < 3; i++) {
            t[i] = cin.nextInt();
        }

        Arrays.sort(t);

        BigInteger[] T = new BigInteger[3];
        T[0] = BigInteger.valueOf(t[0]);
        T[1] = BigInteger.valueOf(t[1]);
        T[2] = BigInteger.valueOf(t[2]);

        BigInteger[] W = new BigInteger[6];

        W[0] = T[0].add(T[1]);
        W[1] = T[1].add(T[2]);
        W[2] = T[2].add(T[0]);
        W[3] = T[1].subtract(T[0]);
        W[4] = T[2].subtract(T[1]);
        W[5] = T[2].subtract(T[0]);

        BigInteger L = W[0];

        for (int i = 0; i < 6; i++) {
            L = lcm(L, W[i]);
        }

        BigInteger[] S = new BigInteger[6];

        S[0] = L.multiply(T[0]).multiply(T[1]).divide(W[0]);
        S[1] = L.multiply(T[1]).multiply(T[2]).divide(W[1]);
        S[2] = L.multiply(T[2]).multiply(T[0]).divide(W[2]);
        S[3] = L.multiply(T[0]).multiply(T[1]).divide(W[3]);
        S[4] = L.multiply(T[1]).multiply(T[2]).divide(W[4]);
        S[5] = L.multiply(T[2]).multiply(T[0]).divide(W[5]);

        BigInteger[] n = new BigInteger[8];

        n[0] = lcm(S[0], S[1], S[2]);
        n[1] = lcm(S[3], S[1], S[2]);
        n[2] = lcm(S[0], S[4], S[2]);
        n[3] = lcm(S[3], S[4], S[2]);
        n[4] = lcm(S[0], S[1], S[5]);
        n[5] = lcm(S[3], S[1], S[5]);
        n[6] = lcm(S[0], S[4], S[5]);
        n[7] = lcm(S[3], S[4], S[5]);

        BigInteger x = n[0];

        for (int i = 0; i < 8; i++) {
            x = x.min(n[i]);
        }

        BigInteger g = x.gcd(L);

        x = x.divide(g);
        L = L.divide(g);

        System.out.println(x + "/" + L);
    }

    static BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(a.gcd(b));
    }

    static BigInteger lcm(BigInteger a, BigInteger b, BigInteger c) {
        return lcm(a, lcm(b, c));
    }
}
0