結果

問題 No.894 二種類のバス
ユーザー htensaihtensai
提出日時 2019-11-11 12:18:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 1,000 ms
コード長 456 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 71,912 KB
実行使用メモリ 56,540 KB
最終ジャッジ日時 2023-10-13 07:59:37
合計ジャッジ時間 5,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,676 KB
testcase_01 AC 110 ms
56,316 KB
testcase_02 AC 110 ms
56,024 KB
testcase_03 AC 110 ms
55,844 KB
testcase_04 AC 108 ms
55,760 KB
testcase_05 AC 114 ms
55,528 KB
testcase_06 AC 112 ms
56,060 KB
testcase_07 AC 112 ms
56,264 KB
testcase_08 AC 114 ms
54,336 KB
testcase_09 AC 113 ms
55,820 KB
testcase_10 AC 112 ms
55,936 KB
testcase_11 AC 110 ms
55,852 KB
testcase_12 AC 109 ms
55,860 KB
testcase_13 AC 110 ms
56,268 KB
testcase_14 AC 111 ms
55,972 KB
testcase_15 AC 111 ms
56,328 KB
testcase_16 AC 112 ms
55,928 KB
testcase_17 AC 111 ms
55,924 KB
testcase_18 AC 113 ms
56,540 KB
testcase_19 AC 120 ms
55,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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 count = (t - 1) / a + (t - 1) / b;
		count -= (t - 1) / a / (b /gcd(a, b));
		System.out.println(count + 1);
	}
	
	static long gcd(long a, long b) {
	    if (a % b == 0) {
	        return b;
	    } else {
	        return gcd(b, a % b);
	    }
	}
}
0