結果

問題 No.894 二種類のバス
ユーザー tentententen
提出日時 2020-08-29 12:40:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 39 ms / 1,000 ms
コード長 875 bytes
コンパイル時間 3,397 ms
コンパイル使用メモリ 72,352 KB
実行使用メモリ 33,472 KB
最終ジャッジ日時 2023-08-09 00:21:19
合計ジャッジ時間 6,224 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
33,208 KB
testcase_01 AC 37 ms
33,432 KB
testcase_02 AC 37 ms
33,192 KB
testcase_03 AC 37 ms
33,472 KB
testcase_04 AC 37 ms
33,428 KB
testcase_05 AC 37 ms
33,192 KB
testcase_06 AC 37 ms
33,472 KB
testcase_07 AC 37 ms
33,176 KB
testcase_08 AC 39 ms
33,256 KB
testcase_09 AC 37 ms
33,152 KB
testcase_10 AC 37 ms
33,200 KB
testcase_11 AC 37 ms
33,252 KB
testcase_12 AC 37 ms
33,168 KB
testcase_13 AC 37 ms
33,232 KB
testcase_14 AC 37 ms
33,192 KB
testcase_15 AC 37 ms
33,064 KB
testcase_16 AC 37 ms
33,188 KB
testcase_17 AC 36 ms
33,424 KB
testcase_18 AC 36 ms
33,220 KB
testcase_19 AC 37 ms
33,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws Exception{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String[] first = br.readLine().split(" ", 3);
    	long t = Long.parseLong(first[0]) - 1;
    	long a = Long.parseLong(first[1]);
     	long b = Long.parseLong(first[2]);
     	long ans = t / a + t / b - t / getLCM(a, b) + 1;
     	System.out.println(ans);
    }
    
    static long getLCM(long a, long b) {
        long gcd = getGCD(a, b);
        long ans = a / gcd;
        if (Long.MAX_VALUE / b <= ans) {
            return Long.MAX_VALUE;
        } else {
            return ans * b;
        }
    }
    
    static long getGCD(long a, long b) {
        if (a % b == 0) {
            return b;
        } else {
            return getGCD(b, a % b);
        }
    }
}
0