結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー htensaihtensai
提出日時 2020-06-04 13:27:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 738 bytes
コンパイル時間 3,288 ms
コンパイル使用メモリ 88,636 KB
実行使用メモリ 55,000 KB
最終ジャッジ日時 2024-11-28 19:59:19
合計ジャッジ時間 5,412 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
54,680 KB
testcase_01 AC 126 ms
54,572 KB
testcase_02 AC 135 ms
54,936 KB
testcase_03 AC 132 ms
54,040 KB
testcase_04 WA -
testcase_05 AC 144 ms
55,000 KB
testcase_06 AC 135 ms
54,760 KB
testcase_07 AC 152 ms
54,768 KB
testcase_08 AC 151 ms
54,500 KB
testcase_09 AC 139 ms
54,912 KB
testcase_10 AC 134 ms
54,900 KB
testcase_11 AC 138 ms
54,356 KB
testcase_12 AC 136 ms
54,920 KB
testcase_13 AC 138 ms
54,848 KB
testcase_14 AC 130 ms
54,468 KB
testcase_15 AC 136 ms
53,844 KB
testcase_16 AC 145 ms
54,908 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