結果

問題 No.415 ぴょん
ユーザー 37zigen37zigen
提出日時 2016-08-24 17:11:49
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 764 bytes
コンパイル時間 3,066 ms
コンパイル使用メモリ 77,780 KB
実行使用メモリ 61,024 KB
最終ジャッジ日時 2024-04-25 15:05:00
合計ジャッジ時間 8,787 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
61,024 KB
testcase_01 AC 106 ms
53,148 KB
testcase_02 AC 104 ms
53,080 KB
testcase_03 AC 105 ms
52,900 KB
testcase_04 AC 116 ms
53,232 KB
testcase_05 AC 123 ms
54,104 KB
testcase_06 AC 124 ms
53,860 KB
testcase_07 AC 108 ms
52,892 KB
testcase_08 AC 106 ms
52,784 KB
testcase_09 AC 114 ms
54,024 KB
testcase_10 AC 111 ms
53,208 KB
testcase_11 AC 108 ms
53,012 KB
testcase_12 AC 114 ms
53,180 KB
testcase_13 AC 123 ms
54,136 KB
testcase_14 AC 118 ms
54,172 KB
testcase_15 AC 109 ms
53,064 KB
testcase_16 AC 119 ms
53,992 KB
testcase_17 AC 116 ms
54,148 KB
testcase_18 AC 107 ms
53,048 KB
testcase_19 AC 115 ms
52,972 KB
testcase_20 AC 126 ms
54,156 KB
testcase_21 AC 121 ms
54,128 KB
testcase_22 AC 118 ms
54,108 KB
testcase_23 AC 117 ms
54,160 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

package No400番台;

import java.util.Scanner;

public class Q415 {
	public static void main(String[] args) {
		new Q415().solver();
	}
	void solver() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long D = sc.nextLong();
		System.out.println(N / gcd(D, N) -1);
	}

	static long gcd(long a, long b) {
		int e = 0;
		while ((a & 1) == 0 && (b & 1) == 0) {
			a >>= 1;
			b >>= 1;
			e++;
		}
		a = reduce(a);
		b = reduce(b);

		while (b != 0 && b != 1) {
			long c = Math.abs(a - b);
			a = Math.min(a, b);
			b = c;
		}
		if (b == 0) {
			return (1 << e) * a;
		} else if (b == 1) {
			return 1 << e;
		} else {
			throw new AssertionError(b);
		}
	}

	static long reduce(long a) {
		while ((a & 1) == 0) {
			a >>= 1;
		}
		return a;
	}
}
0