結果
問題 | No.1486 ロボット |
ユーザー | ks2m |
提出日時 | 2021-04-23 21:25:30 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 144 ms / 2,000 ms |
コード長 | 791 bytes |
コンパイル時間 | 2,287 ms |
コンパイル使用メモリ | 77,856 KB |
実行使用メモリ | 54,352 KB |
最終ジャッジ日時 | 2024-07-04 07:34:20 |
合計ジャッジ時間 | 5,322 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt(); int e = sc.nextInt(); sc.close(); int ab = a + b; int cd = c + d; int x = lcm(ab, cd); int ans = 0; for (int i = 0; i < x; i++) { if (i % ab < a && i % cd < c) { ans++; } } ans *= e / x; e %= x; for (int i = 0; i < e; i++) { if (i % ab < a && i % cd < c) { ans++; } } System.out.println(ans); } static int lcm(long a, long b) { BigInteger ba = BigInteger.valueOf(a); BigInteger bb = BigInteger.valueOf(b); return ba.multiply(bb).divide(ba.gcd(bb)).intValue(); } }