Notice
Recent Posts
Recent Comments
Today
Total
01-26 01:17
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ3] ๋‚˜๋จธ์ง€๊ฐ€ 1์ด ๋˜๋Š” ์ˆ˜ ์ฐพ๊ธฐ ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[์›”๊ฐ„ ์ฝ”๋“œ ์ฑŒ๋ฆฐ์ง€ ์‹œ์ฆŒ3] ๋‚˜๋จธ์ง€๊ฐ€ 1์ด ๋˜๋Š” ์ˆ˜ ์ฐพ๊ธฐ

WonderJay 2022. 7. 5. 16:42
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/87389

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

 

์ฃผ์–ด์ง„ ์ž์—ฐ์ˆ˜๋ฅผ ๋‚˜๋ˆ„์—ˆ์„๋•Œ ๋‚˜๋จธ์ง€๊ฐ€ 1์ด ๋˜๋„๋ก ํ•˜๋Š” ๊ฐ€์žฅ ์ž‘์€ ์ˆ˜ X ๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

 

 

[C++]

#include <bits/stdc++.h>
#define fastio cin.tie(0)->sync_with_stdio(0)

using namespace std;

int solution(int n) {
    fastio;

    int answer = 0;

    for (int i = 1; i <= n; i++)
    {
        if (n % i == 1)
        {
            answer = i;
            break;
        }
    }

    return answer;
}

728x90
๋ฐ˜์‘ํ˜•
LIST
Comments