結果

問題 No.894 二種類のバス
ユーザー lunnearlunnear
提出日時 2019-10-21 19:20:57
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 992 bytes
コンパイル時間 1,926 ms
コンパイル使用メモリ 73,824 KB
実行使用メモリ 58,272 KB
最終ジャッジ日時 2023-09-15 15:06:32
合計ジャッジ時間 5,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 135 ms
56,260 KB
testcase_16 WA -
testcase_17 AC 135 ms
56,064 KB
testcase_18 RE -
testcase_19 AC 136 ms
56,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.math.BigDecimal;

public class Main
{
    public static void main(String[] args) throws Exception
	{
		Scanner scanner = new Scanner(System.in);
		
		BigDecimal t = scanner.nextBigDecimal();
		BigDecimal x = scanner.nextBigDecimal();
		BigDecimal y = scanner.nextBigDecimal();
		BigDecimal z = lcm(x, y);
		
		scanner.close();
		
		BigDecimal ans = BigDecimal.ZERO;
		
		ans = ans.add(t.divide(x));
		ans = ans.add(t.divide(y));
		ans = ans.subtract(t.divide(z));
		
		System.out.println(ans.toPlainString());
    }
    
    private static BigDecimal gcd(BigDecimal x, BigDecimal y)
	{
		if (x.compareTo(y) < 0)
			return _gcd(y, x);
		
		return _gcd(x, y);
	}
	
	private static BigDecimal _gcd(BigDecimal x, BigDecimal y)
	{
		BigDecimal r = x.remainder(y);
		if(r.compareTo(BigDecimal.ZERO) == 0)
			return y;
		
		return _gcd(y, r);
	}
	
	private static BigDecimal lcm(BigDecimal x, BigDecimal y)
	{
	    return x.multiply(y).divide(gcd(x, y));
	}
}

0