문제 링크입니다: https://programmers.co.kr/learn/courses/30/lessons/87389
코딩테스트 연습 - 나머지가 1이 되는 수 찾기
자연수 n이 매개변수로 주어집니다. n을 x로 나눈 나머지가 1이 되도록 하는 가장 작은 자연수 x를 return 하도록 solution 함수를 완성해주세요. 답이 항상 존재함은 증명될 수 있습니다. 제한사항 입
programmers.co.kr
간단한 구현 문제였습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <vector> | |
using namespace std; | |
int solution(int n) { | |
for (int x = 2; ; x++) | |
{ | |
if (n % x == 1) | |
{ | |
return x; | |
} | |
} | |
} |

개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > programmers' 카테고리의 다른 글
[Programmers] n^2 배열 자르기 (1) | 2021.10.28 |
---|---|
[Programmers 위클리 챌린지 12주차] 피로도 (2) | 2021.10.25 |
[Programmers 위클리 챌린지 11주차] 아이템 줍기 (2) | 2021.10.20 |
[Programmers 위클리 챌린지 10주차] 교점에 별 만들기 (0) | 2021.10.14 |
[Programmers] 빛의 경로 사이클 (0) | 2021.10.09 |