結果

問題 No.415 ぴょん
ユーザー nihi9119nihi9119
提出日時 2017-06-20 17:38:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 2,106 bytes
コンパイル時間 3,595 ms
コンパイル使用メモリ 76,808 KB
実行使用メモリ 37,048 KB
最終ジャッジ日時 2024-04-29 11:49:11
合計ジャッジ時間 5,966 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,948 KB
testcase_01 AC 51 ms
36,628 KB
testcase_02 AC 51 ms
36,548 KB
testcase_03 AC 51 ms
36,992 KB
testcase_04 AC 51 ms
36,572 KB
testcase_05 AC 54 ms
36,912 KB
testcase_06 AC 52 ms
36,436 KB
testcase_07 AC 52 ms
36,864 KB
testcase_08 AC 53 ms
36,808 KB
testcase_09 AC 52 ms
37,008 KB
testcase_10 AC 54 ms
36,720 KB
testcase_11 AC 52 ms
36,916 KB
testcase_12 AC 52 ms
36,432 KB
testcase_13 AC 52 ms
36,964 KB
testcase_14 AC 53 ms
36,640 KB
testcase_15 AC 53 ms
36,628 KB
testcase_16 AC 52 ms
36,624 KB
testcase_17 AC 52 ms
36,816 KB
testcase_18 AC 53 ms
36,684 KB
testcase_19 AC 52 ms
37,048 KB
testcase_20 AC 52 ms
36,560 KB
testcase_21 AC 52 ms
36,924 KB
testcase_22 AC 52 ms
36,492 KB
testcase_23 AC 52 ms
36,836 KB
testcase_24 AC 55 ms
36,832 KB
testcase_25 AC 52 ms
36,684 KB
testcase_26 AC 53 ms
36,988 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test8;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * No.415 ぴょん
 * https://yukicoder.me/problems/no/415
 */

public class Question_23_0619 {

	final static int PLACE_MIN = 1; //足場
	final static int INTERVAL_MIN = 1; //1ぴょん幅
	final static int PLACE_MAX = (int)Math.pow(10, 9) * 2;
	static int INTERVAL_MAX;

	public static void main(String[] args) {
		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {
			String[] inputStrArray = br.readLine().split(" ");
			int place = Integer.parseInt(inputStrArray[0]);
			int interval = Integer.parseInt(inputStrArray[1]);
			INTERVAL_MAX = place;

			//有効値判定
			if (NumJudg(place, PLACE_MIN, PLACE_MAX) && NumJudg(interval, INTERVAL_MIN, INTERVAL_MAX)) {
				//placeを最大公約数で割り1を引く
				System.out.println(place / returnGcd(place, interval) - 1);
			} else {
				System.out.println("入力値が有効範囲外です");
			}

		} catch (NumberFormatException e){
			System.out.println("数字を入力して下さい");
		} catch (IOException e) {
			System.out.println("エラーが発生しました");
		} finally {
			try {
				re.close();
				br.close();
			} catch (IOException e) {
				System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
			}
		}
	}

	/**
	 * 有効値判定
	 * @param input 判定するもの
	 * @param max 最大値
	 * @param min 最小値
	 * @return 範囲内ならtrue,範囲外ならfalseを返す
	 */
	private static boolean NumJudg(int input, int min, int max) {
		Boolean result = false;
		if (min <= input && input <= max) {
			result = true;
		}
		return result;
	}

	/**
	 * 最大公約数を返す(ユークリッドの互除法)
	 * @param place
	 * @param interval
	 * @return
	 */
	private static int returnGcd(int place, int interval) {
		while ((place % interval) != 0) {
			int remainder = place % interval; //余り
			place = interval;
			interval = remainder;
		}
		return interval;
	}
}
0