結果

問題 No.1218 Something Like a Theorem
ユーザー ks2mks2m
提出日時 2020-09-04 21:54:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,019 bytes
コンパイル時間 3,755 ms
コンパイル使用メモリ 73,880 KB
実行使用メモリ 56,420 KB
最終ジャッジ日時 2023-08-17 15:33:01
合計ジャッジ時間 5,137 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,768 KB
testcase_01 AC 119 ms
55,828 KB
testcase_02 AC 117 ms
55,756 KB
testcase_03 AC 119 ms
55,872 KB
testcase_04 AC 116 ms
56,296 KB
testcase_05 AC 120 ms
55,784 KB
testcase_06 AC 121 ms
56,420 KB
testcase_07 AC 121 ms
55,800 KB
testcase_08 AC 121 ms
55,772 KB
testcase_09 AC 127 ms
55,936 KB
testcase_10 AC 120 ms
56,020 KB
testcase_11 AC 120 ms
55,684 KB
testcase_12 AC 120 ms
55,776 KB
testcase_13 AC 119 ms
56,356 KB
testcase_14 AC 119 ms
55,528 KB
testcase_15 AC 118 ms
55,944 KB
testcase_16 AC 118 ms
55,536 KB
testcase_17 AC 119 ms
56,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int z = sc.nextInt();
		sc.close();

		long zn = power(z, n);
		for (int x = 1; x < z; x++) {
			long xn = power(x, n);
			long yn = zn - xn;
			long y = root(yn, n);
			if (power(y, n) == yn) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

	static long power(long x, long n) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2);
		val = val * val;
		if (n % 2 == 1) {
			val = val * x;
		}
		return val;
	}

	static int root(long x, int n) {
		int ng = 1000000001;
		int ok = 1;
		while (ng - ok > 1) {
			int mid = (ok + ng) / 2;
			if (Math.pow(mid, n) <= Long.MAX_VALUE) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		ng = ok + 1;
		ok = 1;
		while (ng - ok > 1) {
			int mid = (ok + ng) / 2;
			if (power(mid, n) <= x) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		return ok;
	}
}
0