結果

問題 No.1063 ルートの計算 / Sqrt Calculation
ユーザー htensaihtensai
提出日時 2020-06-04 13:28:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 739 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 84,436 KB
実行使用メモリ 42,592 KB
最終ジャッジ日時 2024-05-06 13:21:23
合計ジャッジ時間 6,345 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
42,256 KB
testcase_01 AC 153 ms
42,296 KB
testcase_02 AC 165 ms
42,308 KB
testcase_03 AC 153 ms
42,316 KB
testcase_04 AC 154 ms
42,268 KB
testcase_05 AC 155 ms
42,120 KB
testcase_06 AC 155 ms
42,452 KB
testcase_07 AC 154 ms
42,452 KB
testcase_08 AC 154 ms
42,592 KB
testcase_09 AC 143 ms
41,956 KB
testcase_10 AC 143 ms
41,912 KB
testcase_11 AC 154 ms
42,332 KB
testcase_12 AC 158 ms
42,280 KB
testcase_13 AC 153 ms
42,208 KB
testcase_14 AC 142 ms
41,956 KB
testcase_15 AC 140 ms
42,148 KB
testcase_16 AC 154 ms
42,148 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