結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー htensaihtensai
提出日時 2020-06-04 13:27:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 738 bytes
コンパイル時間 2,703 ms
コンパイル使用メモリ 87,948 KB
実行使用メモリ 42,468 KB
最終ジャッジ日時 2024-05-06 13:16:30
合計ジャッジ時間 5,849 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
41,864 KB
testcase_01 AC 134 ms
42,228 KB
testcase_02 AC 131 ms
41,928 KB
testcase_03 AC 135 ms
42,468 KB
testcase_04 WA -
testcase_05 AC 140 ms
41,784 KB
testcase_06 AC 125 ms
41,852 KB
testcase_07 AC 136 ms
42,068 KB
testcase_08 AC 142 ms
42,192 KB
testcase_09 AC 134 ms
42,072 KB
testcase_10 AC 126 ms
41,740 KB
testcase_11 AC 136 ms
42,376 KB
testcase_12 AC 137 ms
42,080 KB
testcase_13 AC 139 ms
42,016 KB
testcase_14 AC 133 ms
42,236 KB
testcase_15 AC 125 ms
42,036 KB
testcase_16 AC 137 ms
42,220 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