-
Notifications
You must be signed in to change notification settings - Fork 0
[정수론] 9월 23일 #5
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
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uC815\uC218\uB860-\uBC0F-\uC870\uD569\uB860"
[정수론] 9월 23일 #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
|
|
||
| #include <iostream> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n, k, ans = 1; | ||
| cin >> n >> k; | ||
|
|
||
| for(int i=0; i<k; i++){ | ||
| ans *= n; | ||
| n--; | ||
| } | ||
|
|
||
| int temp = k; | ||
| for(int i=0; i<k; i++){ | ||
| ans /= temp; | ||
| temp--; | ||
| } | ||
|
|
||
| cout << ans; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #include <iostream> | ||
| #include <stack> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| int n, p; | ||
| cin >> n >> p; | ||
|
|
||
| stack<int> line[7]; | ||
|
|
||
| int ans = 0; | ||
| for(int i=0; i<n; i++){ | ||
| int k, v; | ||
| cin >> k >> v; | ||
| //줄에 눌린 프렛이 없을 때 | ||
| if(line[k].empty()){ | ||
| line[k].push(v); | ||
| ans++; | ||
| } | ||
| //더 낮은 프렛이 눌려있을 때 | ||
| else if(v > line[k].top()){ | ||
|
Comment on lines
+17
to
+22
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 두 조건도 같은 일을 하고 있으니 합칠 수 있구요! |
||
| line[k].push(v); | ||
| ans++; | ||
| continue; | ||
| } | ||
| //더 높은 프렛이 눌려있을 때 | ||
| else if(v < line[k].top()){ | ||
| while(!line[k].empty() && v < line[k].top()){ | ||
|
Comment on lines
+28
to
+29
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 2개는 합칠 수 있겠네요! |
||
| line[k].pop(); | ||
| ans++; | ||
| } | ||
| if(line[k].empty() || line[k].top() != v) { | ||
| line[k].push(v); | ||
| ans++; | ||
| } | ||
| } | ||
| } | ||
| cout << ans; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #include <iostream> | ||
| #include <cmath> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int main(){ | ||
| cin.tie(NULL); | ||
| ios::sync_with_stdio(0); | ||
|
|
||
| vector<bool> is_prime(1000001, true); | ||
|
Comment on lines
+10
to
+11
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 숫자를 바로 쓰는 것보단 상수로 선언해서 쓰는게 좋아요! |
||
| //에라토스테네스의 체 | ||
| for(int i=2; i<=sqrt(1000001); i++){ | ||
| if(is_prime[i]){ | ||
| for(int j=i*i; j<=1000001; j += i){ | ||
| is_prime[j] = false; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+12
to
+19
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분은 에라토스테네스의 체 연산 부분이니 함수로 만들어주세요 |
||
|
|
||
| while(true){ | ||
| int n, a, b; | ||
| cin >> n; | ||
|
|
||
| if(n == 0) | ||
| break; | ||
|
|
||
| for(int i=3; i<=n/2; i++){ | ||
|
Comment on lines
+27
to
+28
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. n/2까지만 돌아도 된다는걸 캐치하셨네요! 3부터 시작해도 된다는 것두요! |
||
| if(is_prime[i] && is_prime[n-i]) { | ||
| a = i; | ||
| b = n - i; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| cout << n << " = " << a << " + " << b << '\n'; | ||
|
|
||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #include <iostream> | ||
| #include <set> | ||
| #include <vector> | ||
|
|
||
| using namespace std; | ||
|
|
||
| int getGcd(int a, int b){ | ||
| if(b == 0) | ||
| return a; | ||
| return getGcd(b, a%b); | ||
| } | ||
|
|
||
| int main(){ | ||
| int t; | ||
| cin >> t; | ||
|
|
||
| for(int i=0; i<t; i++){ | ||
| int n, sum = 0; | ||
| cin >> n; | ||
| vector<int> num(n, 0); | ||
| for(int j=0; j<n; j++){ | ||
| cin >> num[j]; | ||
| } | ||
| for(int j=0; j<n-1; j++){ | ||
| for(int k=j+1; k<n; k++){ | ||
| sum += (getGcd(num[j], num[k])); | ||
| } | ||
| } | ||
|
|
||
| cout << sum << '\n'; | ||
| } | ||
| } |
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.
이 문제는 간단해서 이렇게 풀어도 괜찮지만, 사실 이건 하드코딩에 가깝습니다!
이항계수 공식이나 파스칼의 삼각형을 이용해서 코드를 정리하는게 좋아요