728x90
SMALL

using System;

public class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for(int i = 2;i<n;i++)
        {
            if(n%i == 1)
            {
                answer = i;
                return i;
            }
        }
        
        return answer;
    }
}

 

파이썬

////

 

def solution(n):

    if not 3 <= n <= 1000000 :
        return False

    answer = 2
    while True :
        if n % answer == 1 :
            break
        else :
            answer += 1

    return answer

 

def solution(n):
    answer = min([x for x in range(1, n+1) if n % x == 1])
    return answer

 

자바

/////

 

class Solution {
    public int solution(int n) {
        int answer = 0;
        
        for (int i=2; i<n; i++) 
        {
            if (n % i == 1) 
            {
                answer = i;
                break;
            } 
        }
        return answer;
    }
}
728x90

설정

트랙백

댓글