結果

問題 No.894 二種類のバス
ユーザー k_6101k_6101
提出日時 2019-12-05 20:22:17
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,800 bytes
コンパイル時間 3,296 ms
コンパイル使用メモリ 75,180 KB
実行使用メモリ 56,028 KB
最終ジャッジ日時 2023-08-23 13:13:44
合計ジャッジ時間 6,064 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,652 KB
testcase_01 AC 122 ms
55,780 KB
testcase_02 AC 119 ms
55,488 KB
testcase_03 AC 118 ms
55,852 KB
testcase_04 AC 119 ms
55,704 KB
testcase_05 AC 119 ms
55,832 KB
testcase_06 AC 120 ms
55,388 KB
testcase_07 AC 120 ms
55,700 KB
testcase_08 AC 120 ms
55,632 KB
testcase_09 AC 119 ms
53,868 KB
testcase_10 AC 119 ms
55,708 KB
testcase_11 AC 119 ms
55,932 KB
testcase_12 AC 119 ms
55,792 KB
testcase_13 AC 119 ms
55,620 KB
testcase_14 AC 119 ms
55,484 KB
testcase_15 WA -
testcase_16 AC 120 ms
55,688 KB
testcase_17 WA -
testcase_18 AC 122 ms
55,868 KB
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

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);
    	ans += (T / B - (T % B == 0 ? 1 : 0));
//    	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));
    	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