結果

問題 No.894 二種類のバス
ユーザー k_6101k_6101
提出日時 2019-12-05 19:50:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 1,000 ms
コード長 1,714 bytes
コンパイル時間 3,364 ms
コンパイル使用メモリ 75,112 KB
実行使用メモリ 55,928 KB
最終ジャッジ日時 2023-08-23 12:40:45
合計ジャッジ時間 7,511 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,588 KB
testcase_01 AC 122 ms
55,812 KB
testcase_02 AC 122 ms
55,820 KB
testcase_03 AC 122 ms
55,800 KB
testcase_04 AC 123 ms
55,496 KB
testcase_05 AC 123 ms
55,704 KB
testcase_06 AC 119 ms
55,664 KB
testcase_07 AC 122 ms
55,820 KB
testcase_08 AC 121 ms
55,616 KB
testcase_09 AC 122 ms
55,796 KB
testcase_10 AC 121 ms
55,928 KB
testcase_11 AC 120 ms
55,468 KB
testcase_12 AC 121 ms
55,840 KB
testcase_13 AC 120 ms
55,636 KB
testcase_14 AC 119 ms
55,484 KB
testcase_15 AC 122 ms
55,696 KB
testcase_16 AC 121 ms
55,624 KB
testcase_17 AC 121 ms
55,452 KB
testcase_18 AC 124 ms
55,928 KB
testcase_19 AC 122 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));
    	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