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 |
Tags
- kotlin
- activity
- CoordinatorLayout
- hilt
- lifecycle
- LiveData
- Coroutine
- CustomView
- BOJ
- Navigation
- recyclerview
- AppBarLayout
- Algorithm
- CollapsingToolbarLayout
- Android
- 알림
- onMeasure
- room
- HTTP
- View
- DataBinding
- 안드로이드
- ViewModel
- notification
- sqlite
- onLayout
- Behavior
- 알고리즘
- 코틀린
- 백준
Archives
- Today
- Total
개발일지
Algorithm - Fermat's little theorem(페르마의 소정리) 본문
개념
If is prime and is an integer not divisible by , then
문제
16134 조합
코드
#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