結果

問題 No.894 二種類のバス
ユーザー lavoxlavox
提出日時 2021-11-19 19:40:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 43 ms / 1,000 ms
コード長 2,377 bytes
コンパイル時間 4,384 ms
コンパイル使用メモリ 73,804 KB
実行使用メモリ 49,636 KB
最終ジャッジ日時 2023-08-30 04:38:51
合計ジャッジ時間 5,632 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
48,984 KB
testcase_01 AC 42 ms
49,068 KB
testcase_02 AC 42 ms
49,020 KB
testcase_03 AC 43 ms
49,088 KB
testcase_04 AC 43 ms
48,964 KB
testcase_05 AC 43 ms
49,044 KB
testcase_06 AC 43 ms
49,196 KB
testcase_07 AC 42 ms
49,012 KB
testcase_08 AC 42 ms
49,636 KB
testcase_09 AC 43 ms
48,804 KB
testcase_10 AC 42 ms
49,048 KB
testcase_11 AC 43 ms
49,072 KB
testcase_12 AC 43 ms
49,184 KB
testcase_13 AC 42 ms
49,284 KB
testcase_14 AC 42 ms
49,036 KB
testcase_15 AC 43 ms
49,012 KB
testcase_16 AC 43 ms
49,076 KB
testcase_17 AC 42 ms
49,068 KB
testcase_18 AC 43 ms
49,192 KB
testcase_19 AC 42 ms
49,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		Main o = new Main();
		o.solve();
	}

	public void solve() {
		FastScanner sc = new FastScanner(System.in);
		long T = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();

		long g = gcd(A, B);

		long ans = (T - 1L) / A + (T - 1L) / B - (T - 1L) / (A / g) / B + 1L;

		System.out.println(ans);
	}
	// 最大公約数を計算する
	static long gcd(long a, long b) {
		while ( b != 0 ) {
			long tmp = b;
			b = a % b;
			a = tmp;
		}
		return a;
	}

	class FastScanner {
		private final InputStream in;
		private final byte[] buf = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		FastScanner( InputStream source ) { this.in = source; }
		private boolean hasNextByte() {
			if ( ptr < buflen ) return true;
			else {
				ptr = 0;
				try { buflen = in.read(buf); } catch (IOException e) { e.printStackTrace(); }
				if ( buflen <= 0 ) return false;
			}
			return true;
		} 
		private int readByte() { if ( hasNextByte() ) return buf[ptr++]; else return -1; } 
		private boolean isPrintableChar( int c ) { return 33 <= c && c <= 126; }
		private boolean isNumeric( int c ) { return '0' <= c && c <= '9'; }
		private void skipToNextPrintableChar() { while ( hasNextByte() && !isPrintableChar(buf[ptr]) ) ptr++; }
		public boolean hasNext() { skipToNextPrintableChar(); return hasNextByte(); }
		public String next() {
			if ( !hasNext() ) throw new NoSuchElementException();
			StringBuilder ret = new StringBuilder();
			int b = readByte();
			while ( isPrintableChar(b) ) { ret.appendCodePoint(b); b = readByte(); }
			return ret.toString();
		}
		public long nextLong() {
			if ( !hasNext() ) throw new NoSuchElementException();
			long ret = 0;
			int b = readByte();
			boolean negative = false;
			if ( b == '-' ) { negative = true; if ( hasNextByte() ) b = readByte(); }
			if ( !isNumeric(b) ) throw new NumberFormatException();
			while ( true ) {
				if ( isNumeric(b) ) ret = ret * 10 + b - '0';
				else if ( b == -1 || !isPrintableChar(b) ) return negative ? -ret : ret;
				else throw new NumberFormatException();
				b = readByte();
			}
		}
		public int nextInt() { return (int)nextLong(); }
		public double nextDouble() { return Double.parseDouble(next()); }
	}
}
0