結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー htensaihtensai
提出日時 2020-06-04 13:28:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 2,572 ms
コンパイル使用メモリ 75,276 KB
実行使用メモリ 57,240 KB
最終ジャッジ日時 2023-08-19 06:12:57
合計ジャッジ時間 6,614 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
56,952 KB
testcase_01 AC 158 ms
57,060 KB
testcase_02 AC 154 ms
54,892 KB
testcase_03 AC 155 ms
56,832 KB
testcase_04 AC 135 ms
56,884 KB
testcase_05 AC 130 ms
56,864 KB
testcase_06 AC 129 ms
56,940 KB
testcase_07 AC 133 ms
56,960 KB
testcase_08 AC 130 ms
57,008 KB
testcase_09 AC 131 ms
57,240 KB
testcase_10 AC 132 ms
56,804 KB
testcase_11 AC 133 ms
56,824 KB
testcase_12 AC 129 ms
56,600 KB
testcase_13 AC 134 ms
56,884 KB
testcase_14 AC 130 ms
57,104 KB
testcase_15 AC 140 ms
56,632 KB
testcase_16 AC 128 ms
57,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayDeque<Integer> stack = new ArrayDeque<>();
		for (int i = 1; i <= Math.sqrt(n); i++) {
		    if (n % i == 0) {
		        stack.push(n / i);
		        int x = n / i;
		        if ((int)(Math.sqrt(x)) * (int)(Math.sqrt(x)) == x) {
		            System.out.println((int)(Math.sqrt(x)) + " " + i);
		            return;
		        }
		    }
		}
		while (stack.size() > 0) {
		    int i = stack.pop();
		    int x = n / i;
	        if ((int)(Math.sqrt(x)) * (int)(Math.sqrt(x)) == x) {
	            System.out.println((int)(Math.sqrt(x)) + " " + i);
	            return;
	        }
		}
	}
}
0