結果

問題 No.415 ぴょん
ユーザー GrenacheGrenache
提出日時 2016-08-26 22:55:06
言語 Java19
(openjdk 21)
結果
AC  
実行時間 59 ms / 1,000 ms
コード長 1,715 bytes
コンパイル時間 3,815 ms
コンパイル使用メモリ 75,384 KB
実行使用メモリ 50,660 KB
最終ジャッジ日時 2023-08-11 20:20:23
合計ジャッジ時間 6,509 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
50,268 KB
testcase_01 AC 56 ms
50,244 KB
testcase_02 AC 56 ms
50,244 KB
testcase_03 AC 56 ms
50,188 KB
testcase_04 AC 56 ms
50,396 KB
testcase_05 AC 57 ms
50,188 KB
testcase_06 AC 57 ms
50,184 KB
testcase_07 AC 57 ms
50,196 KB
testcase_08 AC 56 ms
50,660 KB
testcase_09 AC 57 ms
50,236 KB
testcase_10 AC 56 ms
50,392 KB
testcase_11 AC 55 ms
50,240 KB
testcase_12 AC 57 ms
50,076 KB
testcase_13 AC 57 ms
50,372 KB
testcase_14 AC 56 ms
50,624 KB
testcase_15 AC 58 ms
50,192 KB
testcase_16 AC 58 ms
50,384 KB
testcase_17 AC 57 ms
50,372 KB
testcase_18 AC 59 ms
50,648 KB
testcase_19 AC 56 ms
50,168 KB
testcase_20 AC 57 ms
50,512 KB
testcase_21 AC 57 ms
50,236 KB
testcase_22 AC 56 ms
50,324 KB
testcase_23 AC 56 ms
50,208 KB
testcase_24 AC 55 ms
50,172 KB
testcase_25 AC 55 ms
50,184 KB
testcase_26 AC 56 ms
50,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder415 {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	Printer pr = new Printer(System.out);

    	int n = sc.nextInt();
    	int d = sc.nextInt();

    	if (n == 1 || n == d) {
    		pr.println(0);
    	} else {
    		pr.println(lcm(n, d) / d - 1);
    	}

    	pr.close();
        sc.close();
    }

	private static long lcm(long n, long m) {
		return n / gcd(n, m) * m;
	}

	private static long gcd(long n, long m) {
		if (m == 0) {
			return n;
		} else {
			return gcd(m, n % m);
		}
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
//					it = Arrays.asList(br.readLine().split(" ")).iterator();
					it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0