結果

問題 No.894 二種類のバス
ユーザー takeya_okino
提出日時 2019-09-28 11:57:33
言語 Java
(openjdk 23)
結果
AC  
実行時間 137 ms / 1,000 ms
コード長 809 bytes
コンパイル時間 2,323 ms
コンパイル使用メモリ 75,396 KB
実行使用メモリ 41,788 KB
最終ジャッジ日時 2024-10-01 21:03:25
合計ジャッジ時間 4,977 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long t = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();

    long ans = 2 + (t - 1) / a;

    long g = gcd(a, b);
    long g1 = g * (a / g) * (b / g);

    BigDecimal ba = new BigDecimal(a);
    BigDecimal bb = new BigDecimal(b);
    BigDecimal bg = new BigDecimal(g);
    
    BigDecimal ag = ba.multiply(bb);
    ag = ag.divide(bg);

    if((ag.compareTo(new BigDecimal(Long.MAX_VALUE))) <= 0) {
      ans -= (1 + (t - 1) / g1);
    } else {
      ans -= 1;
    }

    ans += (t - 1) / b;

    System.out.println(ans);
  }

  public static long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, (a % b));
  }
}
0