본문 바로가기
알고리즘 & 자료구조/프로그래머스

점 찍기

by 신재권 2023. 3. 16.
package programmers;

public class 점_찍기 {

   public static long solution(int k, int d) {
      long answer = 0;

      for (int x = 0; x <= d; x += k) {
         long nx = (long)Math.pow(x, 2);
         long nd = (long)Math.pow(d, 2);
         int result = (int)Math.sqrt(nd - nx);
         answer += (result / k) + 1;
      }

      return answer;
   }

   public static void main(String[] args) {
      System.out.println(solution(2, 4));
      System.out.println(solution(1, 5));
   }
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

무인도 여행  (1) 2023.03.20
하노이의 탑  (0) 2023.03.17
거리두기 확인하기  (0) 2023.03.15
가장 큰 정사각형 찾기  (0) 2023.03.13
전력망을 둘로 나누기  (0) 2023.03.12