Skip to content

[Algorithm] 나머지가 1이 되는 수 찾기 #72

Description

@hwangJi-dev

💬 문제

[코딩테스트 연습 - 나머지가 1이 되는 수 찾기](https://school.programmers.co.kr/learn/courses/30/lessons/87389)


💬 Idea

  • 2부터 n - 1까지 돌면서 나머지가 1이 되는 수를 찾으면 for문을 종료하고 x를 구한다.

💬 풀이

func solution(_ n:Int)->Int{varx=0foriin2...n -1{if n % i ==1{
x = i
break}}return x
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions