프로그래밍
프로그래머스 C# 피자 나눠먹기 2(두 숫자의 최소공배수, P, J)
노마드선샤인
2022. 12. 30. 14:33
728x90
using System;
public class Solution {
public int solution(int n) {
int answer = 0;
//n과 6의 최소공배수를 찾아서 6으로 나누면 된다.
for(int i=1;i<=n;i++)
{
if(n%i==0 && 6%i==0)
{
answer = i;
}
}
answer = n*6/answer;
return answer/6; //피자의 판 수를 구하니까 6으로 나눈다.
}
}
파이썬
import math
def solution(n):
return (n * 6) // math.gcd(n, 6) // 6
def solution(n):
answer = 1
while 6 * answer % n:
answer += 1
return answer
자바
//////
class Solution {
public int solution(int n) {
int answer = 1;
while(true)
{
if(6*answer%n==0)
break;
answer++;
}
return answer;
}
}
728x90