-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3-kokeunho #14
base: main
Are you sure you want to change the base?
3-kokeunho #14
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ cpp ํ์ด์ ๋๋ค. ๊ณ ์ํ์ จ์๋๋น
code
#include <iostream>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int num;
cin >> num;
while (num != -1) {
vector<int> divisor;
int sum = num;
for (int i = 1; i < num; i++) {
if (num % i == 0) {
divisor.push_back(i);
sum -= i;
}
}
if (!sum) {
cout << num << " = " << divisor[0];
for (int i = 1; i < divisor.size(); i++) cout << " + " << divisor[i];
cout << '\n';
}
else cout << num << " is NOT perfect.\n";
cin >> num;
}
return 0;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ณ ์ํ์ จ์ต๋๋ค. ๋ ์ฌ๋ฏธ์๋ ๋ฌธ์ ๋ ๊ธฐ๋ํ๊ฒ ์ต๋๋ค!
c++ ์ฝ๋๋ณด๊ธฐ
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
while (1) {
cin >> n;
if (n == -1) break;
vector<int> v;
int sum = 0;
for (int i = 1; i < n; i++) {
if (n % i == 0) {
sum += i;
v.push_back(i);
}
}
cout << n;
if (sum != n) cout << " is NOT perfect.\n";
else {
cout << " = " << v[0];
for (int i = 1; i < v.size(); i++) cout << " + " << v[i];
cout << '\n';
}
}
return 0;
}
kokeunho/๊ตฌํ/3-kokeunho.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ตฌํ ๋ฌธ์ ๊ตฐ์.
์ธ์ด๋ฅผ ์ตํ๋ฉด์ ๊ฐ๊ธฐ์ ์ข์ ๋ฌธ์ ๋ผ๊ณ ์๊ฐ ๋ฉ๋๋ค.
์ c++ ์ฝ๋๋ ํ์ด ๋ฐฉ์์ ์๋ฒฝํ ๋์ผํฉ๋๋ค.
๐ ๋ฌธ์ ๋งํฌ
[BOJ] ์ฝ์์ ํฉ https://www.acmicpc.net/problem/9506
โ๏ธ ์์๋ ์๊ฐ
40min
โจ ์๋ ์ฝ๋
-1์ด ์ ๋ ฅ๋๊ธฐ ์ ๊น์ง ์ ์๋ฅผ ์ ๋ ฅ ๋ฐ๊ณ ์์ ์์ธ์ง ํ์ธํฉ๋๋ค.
์ ์ n์ด ์ ๋ ฅ๋์๋ค๋ฉด i์์ n๊น์ง ๋๋ฉด์ n % i๊ฐ 0์ธ ์ฝ์ i๋ฅผ ์ฐพ๊ณ ๋ฆฌ์คํธ factors์ ๋ฃ์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋ชจ๋ ์ฝ์๋ค์ ํฉ(sum)์ด n๊ณผ ๊ฐ๋ค๋ฉด
์๊ตฌ ์์๋๋ก ์ถ๋ ฅํ๊ณ
๊ทธ๋ ์ง ์๋ค๋ฉด is not perfect๋ฅผ ์ถ๋ ฅํฉ๋๋ค.
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
ํ์ด์ฌ ๊ธฐ์ด๋ฅผ ์ข ๋ค์ง๋ ค๊ณ ์ฌ์ด ๋ฌธ์ ๋ก ํ์ด๋ดค์ต๋๋ค.
์ถ๋ ฅ ์์์ ๋ง์ถ๋ ค๊ณ ์ฌ๋ฌ ์ค ์ผ๋๋ฐ
์๋ ๊ฒ ํ ์ค์ด๋ฉด ๋์ผํ ์์์ผ๋ก ์ถ๋ ฅ์ด ๊ฐ๋ฅํ๋ค๊ณ ํฉ๋๋ค...
์ ๋ฌธ์์ด ๋ฆฌ์คํธ์ ๊ฐ ์์๋ฅผ " + "๋ก ๊ตฌ๋ถํ์ฌ ํ๋์ ๋ฌธ์์ด๋ก ๋ง๋ค์ด์ค๋๋ค