結果

問題 No.1486 ロボット
ユーザー ks2mks2m
提出日時 2021-04-23 21:25:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 2,050 ms
コンパイル使用メモリ 79,216 KB
実行使用メモリ 56,376 KB
最終ジャッジ日時 2023-09-17 11:40:04
合計ジャッジ時間 5,819 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,024 KB
testcase_01 AC 126 ms
56,200 KB
testcase_02 AC 124 ms
55,888 KB
testcase_03 AC 123 ms
56,028 KB
testcase_04 AC 123 ms
56,180 KB
testcase_05 AC 123 ms
56,100 KB
testcase_06 AC 132 ms
55,972 KB
testcase_07 AC 135 ms
56,212 KB
testcase_08 AC 134 ms
56,284 KB
testcase_09 AC 125 ms
56,376 KB
testcase_10 AC 125 ms
55,796 KB
testcase_11 AC 125 ms
55,516 KB
testcase_12 AC 124 ms
56,224 KB
testcase_13 AC 122 ms
55,992 KB
testcase_14 AC 138 ms
55,952 KB
testcase_15 AC 127 ms
55,988 KB
testcase_16 AC 133 ms
54,468 KB
testcase_17 AC 135 ms
55,996 KB
testcase_18 AC 131 ms
55,920 KB
testcase_19 AC 124 ms
55,744 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
	}
}
0