結果

問題 No.894 二種類のバス
ユーザー k_6101k_6101
提出日時 2019-12-05 20:31:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 1,875 bytes
コンパイル時間 2,740 ms
コンパイル使用メモリ 75,376 KB
実行使用メモリ 56,048 KB
最終ジャッジ日時 2023-08-23 13:30:55
合計ジャッジ時間 6,464 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,936 KB
testcase_01 AC 120 ms
55,716 KB
testcase_02 AC 120 ms
55,572 KB
testcase_03 AC 120 ms
55,712 KB
testcase_04 AC 121 ms
55,632 KB
testcase_05 AC 120 ms
55,708 KB
testcase_06 AC 124 ms
56,048 KB
testcase_07 AC 120 ms
55,672 KB
testcase_08 AC 121 ms
55,716 KB
testcase_09 AC 122 ms
55,712 KB
testcase_10 AC 119 ms
55,784 KB
testcase_11 AC 120 ms
55,620 KB
testcase_12 AC 120 ms
55,700 KB
testcase_13 AC 120 ms
55,744 KB
testcase_14 AC 121 ms
55,720 KB
testcase_15 AC 122 ms
55,448 KB
testcase_16 AC 121 ms
55,796 KB
testcase_17 AC 120 ms
55,844 KB
testcase_18 AC 118 ms
55,720 KB
testcase_19 AC 120 ms
55,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // 最大公約数の取得			
    long gcd(long a, long b) {			
    	if (b == 0)		
    		return a;	
    	return gcd(b, a % b);		
    }			
    			
    // 最小公倍数の取得			
    long lcm(long a, long b) {			
    	return a / gcd(a, b)  * b;		
    }			

    // ==================================================================
    public void solve() {
    	long T = Long.parseLong(sc.next());
    	long A = Long.parseLong(sc.next());
    	long B = Long.parseLong(sc.next());
    	long ans = T / A - (T % A == 0 ? 1 : 0);
//    	out.println(ans);
    	ans += (T / B - (T % B == 0 ? 1 : 0));
//    	out.println(ans);
//    	long L = lcm(A, B);
//    	out.println("  lcm = " + L);
//    	if(L > 0)	ans -= (T / L - (T % L == 0 ? 1 : 0));
    	long G = gcd(A, B);
//    	out.println(" G = " + G);
    	ans -= ((T / A) / (B / G));
//    	out.println(ans);
    	if(T % A == 0 && T % B == 0)	ans++;
    	out.println(ans+1);
    }
    // ==================================================================
}
class PP{
	public int key, val;
	public PP(int key, int val) {
		this.key = key;
		this.val = val;
	}
	public int getKey() {
		return key;
	}
	public int getVal() {
		return val;
	}
}
0