Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- sqlite
- onLayout
- kotlin
- activity
- notification
- BOJ
- Behavior
- CustomView
- Coroutine
- 알고리즘
- Android
- 코틀린
- onMeasure
- 안드로이드
- CollapsingToolbarLayout
- View
- 백준
- recyclerview
- HTTP
- 알림
- ViewModel
- hilt
- LiveData
- lifecycle
- room
- AppBarLayout
- CoordinatorLayout
- Algorithm
- Navigation
- DataBinding
Archives
- Today
- Total
개발일지
Algorithm - Fermat's little theorem(페르마의 소정리) 본문
개념
If is prime and is an integer not divisible by , then
문제
16134 조합
16134번: 조합 (Combination)
\(\begin{pmatrix}N\\R\end{pmatrix}\)의 값을 1,000,000,007로 나눈 나머지를 출력하자! (단, 1,000,000,007은 소수이다)
www.acmicpc.net
코드
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
long long pow(long long x, long long y) {
long long result = 1L;
while (y) {
if (y & 1) {
result *= x;
result %= MOD;
}
x *= x;
x %= MOD;
y /= 2L;
}
return result;
}
long long permutation(long long n) {
long long result = 1L;
for (long long i = 1L;i <= n;++i) {
result *= i;
result %= MOD;
}
return result;
}
long long combination(long long n, long long r) {
return permutation(n) * pow(permutation(n - r), MOD - 2) % MOD * pow(permutation(r), MOD - 2) % MOD;
}
int main() {
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
long long n, r;
cin >> n >> r;
cout << combination(n, r) << "\n";
}
'Algorithm (알고리즘)' 카테고리의 다른 글
Algorithm in A..Z - BFS (0) | 2020.11.28 |
---|---|
Algorithm in A..Z - Binary Matching (Hopcroft-Karp) (0) | 2020.10.16 |
Algorithm in A..Z - SSC(Tarjans) (0) | 2020.10.07 |
Algorithm in A..Z - SCC(Kosaraju) (0) | 2020.10.07 |
Algorithm - Cut Edge (단절선) (0) | 2020.09.17 |
Comments