"SWEA 5688 세제곱근을 찾아라"의 두 판 사이의 차이

(새 문서: ==개요== ;{{PAGENAME}} {{SWEA 헤더}} {{SWEA 난이도 3-1}} |} ==C++== <source lang='cpp'> </source> ==Java== <source lang='java'> </source>)
 
12번째 줄: 12번째 줄:
==Java==
==Java==
<source lang='java'>
<source lang='java'>
import java.util.*;
class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T;
        T=sc.nextInt();
       
        long N, x;
        for(int test_case = 1; test_case <= T; test_case++) {
            N = sc.nextLong();
            x = (long) Math.floor(Math.cbrt(N));
            if( x*x*x != N ) x = -1;
            System.out.format("#%d %d\n", test_case, x);
        }
        sc.close();
    }
}
</source>
</source>

2018년 12월 19일 (수) 23:15 판

1 개요

SWEA 5688 세제곱근을 찾아라
SW Expert 아카데미
# 문제 풀이

틀:SWEA 난이도 3-1

2 C++

3 Java

import java.util.*;
class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T;
        T=sc.nextInt();
         
        long N, x;
        for(int test_case = 1; test_case <= T; test_case++) {
            N = sc.nextLong();
            x = (long) Math.floor(Math.cbrt(N));
            if( x*x*x != N ) x = -1;
            System.out.format("#%d %d\n", test_case, x);
        }
        sc.close();
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}