์ค๋ฒ3 : ์ํ ๋ฌธ์ ์ด๋ค.
์๊ฐ
์ผ๋จ ์ฝ๋๊ฐ ์ฒ์๋ณด๋ ๊ฑฐ๋ผ ์ ์ฌํ ๋ณด์๋ค. ๊ฒฐ๊ตญ ์ด๋ฐ ๊ฒ์ ๋ฌป๋ ๋ฌธ์ ์๋ค.
๊ฐ์ฅ ํฐ ์ฝ์๊ฐ ๋ค์์ ๋ถํฐ ๋ช๋ฒ์งธ์ ๋์ค๋?
๊ทธ๋ ๋ค๋ฉด ๊ฐ์ฅ ํฐ ์ฝ์๋ฅผ ๊ตฌํด์ผ ํ๋๋ฐ, ๊ฐ์ฅ ํฐ ์ฝ์๋ ์ฌ์ค ๊น์ง๋ง ์กฐ์ฌํด๋ ํ ์ ์๋ค. ๋ชจ๋ ์๋ ์ฝ์๋ก 1์ ๊ฐ์ง๋ฏ๋ก 1์ ์ด๊ธฐ๊ฐ์ผ๋ก ๋๊ณ , ๊น์ง ๋ฃจํ๋ฅผ ๋๋ฉฐ ๊ฐ์ฅ ํฐ ์ฝ์๋ฅผ ๊ตฌํ ๋ค, ๊ทธ ๊ฐ๊น์ง ์ค๋ count ๊ฐ์๋ฅผ ์ถ๋ ฅํ๋ฉด ๋๋ค.
Code
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int n, divisor = 1;
cin >> n;
for (int i = 2; i*i <= n; i++) {
if (n%i == 0) {
divisor = n/i;
break;
}
}
cout << n-divisor << '\n';
}