반응형
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/136798
문제 요약
무기를 만들기 위해 필요한 철의 무게를 반환하는 함수 만들기
풀이
using System;
using System.Linq;
using System.Collections.Generic;
public class Solution {
public int solution(int number, int limit, int power) {
int answer = 0;
int cnt = 0;
for (int i = 1; i <= number; i++)
{
for (int j = 1; j <= Math.Sqrt(i); j++)
{
if (i % j == 0)
{
cnt += 2;
if (i / j == j) cnt--;
}
}
answer += cnt > limit ? power : cnt;
cnt = 0;
}
return answer;
}
}
캔들에서 더 이상 향이 안 난다...
반응형
'Algorithm > Programmers' 카테고리의 다른 글
[C#]프로그래머스 12949 행렬의 곱셈 - Hide (0) | 2024.12.01 |
---|---|
[C#]프로그래머스 42840 모의고사 - Hide (0) | 2024.11.30 |
[C#]프로그래머스 42586 기능개발 - Hide (0) | 2024.11.27 |
[C#]프로그래머스 135808 과일 장수 - Hide (0) | 2024.11.24 |
[C#]프로그래머스 120923 연속된 수의 합 - Hide (0) | 2024.11.23 |