結果

問題 No.1350 2019-6problem
ユーザー tenten
提出日時 2021-01-18 14:20:27
言語 Java
(openjdk 23)
結果
MLE  
実行時間 -
コード長 954 bytes
コンパイル時間 2,601 ms
コンパイル使用メモリ 79,060 KB
実行使用メモリ 516,620 KB
最終ジャッジ日時 2024-12-14 04:03:14
合計ジャッジ時間 57,721 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 4 TLE * 15 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		long lcm = getLCM(a, b);
		long count = lcm / a - 1 + lcm / b;
		int k = sc.nextInt();
		long times = k / count;
		long mod = k % count;
		TreeSet<Long> set = new TreeSet<>();
		for (long i = 1; i * a < lcm; i++) {
		    set.add(i * a);
		}
		for (long i = 1; i * b < lcm; i++) {
		    set.add(i * b);
		}
		if (mod == 0) {
		    long ans = lcm * times;
		    System.out.println(ans);
		} else {
		    long ans = lcm * times;
		    for (int i = 1; i < mod; i++) {
		        set.pollFirst();
		    }
		    ans += set.first();
		    System.out.println(ans);
		}
	}
	
	static long getLCM(long a, long b) {
	    return a / getGCD(a, b) * b;
	}
	
	static long getGCD(long a, long b) {
	    if (a % b == 0) {
	        return b;
	    } else {
	        return getGCD(b, a % b);
	    }
	}
}
0