結果
| 問題 |
No.894 二種類のバス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-19 19:40:44 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 58 ms / 1,000 ms |
| コード長 | 2,377 bytes |
| コンパイル時間 | 2,594 ms |
| コンパイル使用メモリ | 77,752 KB |
| 実行使用メモリ | 50,116 KB |
| 最終ジャッジ日時 | 2024-12-31 13:06:51 |
| 合計ジャッジ時間 | 4,560 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
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()); }
}
}