Deep_Dev

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AXO72aaqPrcDFAXS&categoryId=AXO72aaqPrcDFAXS&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=2 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 

 


a์ด์ƒ b์ดํ•˜๊นŒ์ง€ ๋ฐ˜๋ณตํ•˜๋ฉด์„œ

 

์ •์ˆ˜๋ฅผ ๋ฌธ์ž์—ด๋กœ ๋ฐ”๊ฟ”์„œ

๋ฌธ์ž์—ด = ๋’ค์ง‘์€ ๋ฌธ์ž์—ด ๋น„๊ตํ•ด์„œ ์ฒซ๋ฒˆ์งธ ํŒฐ๋ฆฐ๋“œ๋กฌ ํ™•์ธ

ํŒฐ๋ฆฐ๋“œ๋กฌ์ด ๋งž์œผ๋ฉด ๊ทธ ๋ฌธ์ž์˜ ์ œ๊ณฑ๊ทผ์ด ์ •์ˆ˜๋ผ๋ฉด 

๋‹ค์‹œ ๊ทธ ์ •์ˆ˜= ๋’ค์ง‘์€ ์ •์ˆ˜๋น„๊ตํ•ด์„œ ์นด์šดํŒ…

 

 

 

import java.util.Scanner;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            int a = kb.nextInt();
            int b = kb.nextInt();
            StringBuilder sb;

            int cnt = 0;
            for (int i = a; i <= b; i++) {
                String s = String.valueOf(i);
                sb = new StringBuilder(s).reverse();
                if (s.equals(sb.toString())) { // ์ฒซ๋ฒˆ์งธ ํŒฐ๋ฆฐ๋“œ๋กฌ ํ™•์ธ
                    double temp = Math.sqrt(i); // ์ œ๊ณฑ๊ทผ
                    int num = (int) temp; // ์ œ๊ณฑ์€์„ intํ˜•์œผ๋กœ ๋ฐ”๊ฟ”์„œ
                    if (num * num == i) { // ์ •ํ™•ํžˆ ์ •์ˆ˜ ์ œ๊ณฑ๊ทผ์ด ๋งž์œผ๋ฉด
                        String ss = String.valueOf(num);
                        sb = new StringBuilder(ss).reverse();
                        if (ss.equals(sb.toString())) // ์ œ๊ณฑ๊ทผ ํŒฐ๋ฆฐ๋“œ๋กฌ ํ™•์ธ
                            cnt++;
                    }
                }
            }
            System.out.println("#" + t + " " + cnt);
        }
    }
}