-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11.cpp
More file actions
58 lines (54 loc) · 2.1 KB
/
11.cpp
File metadata and controls
58 lines (54 loc) · 2.1 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
//----------------------------------------------------------------//
// definitions //
#define endl '\n'
//----------------------------------------------------------------//
// preDefined functions//
//number theory //
template<typename T>
bool isPrime( T n ) { if (n <= 1)return false;for (long long i = 2;i * i <= n;++i) { if (!(n % i))return false; }return true; }
template<typename T>
long long factorial( T N ) { long long ans = 1;while (N > 1)ans *= N--;return ans; }
template<typename T, typename Y>
long long NCR( T N, Y R ) { if (R > N)return 0;long long ans = 1, MN = min( R, N - R ), MX = max( R, N - R );while (N > MX) { ans *= N--; }while (MN > 1)ans /= MN--;return ans; }
template<typename T, typename Y>
long long NPR( T N, Y R ) { long long ans = 1, tmp = N - R;while (N > tmp) { ans *= N--; }return ans; }
void sieve( vector<bool>& ans ) { ans[ 0 ] = ans[ 1 ] = false; long long tmp = sqrt( ans.size() ), till = ans.size();for (long long i = 2;i <= tmp;i++)if (ans[ i ])for (long long j = i * i;j < till;j += i)ans[ j ] = false; }
template<typename T>
map<long long, long long> primeFactors( T N ) {
map<long long, long long> ans;
long long till = sqrt( N );
for (long long i = 2; i <= till; i++) {
while (!(N % i)) {
ans[ i ]++;N /= i;
}if (i >= N)break;
}if (N > 1)ans[ N ]++;return ans;
}
//number theory//
//----------------------------------------------------------------//
//data types//
//----------------------------------------------------------------//
// helper functions //
//----------------------------------------------------------------//
// solve function//
void solve()
{
cout << NPR( 10, 7 ) << endl;
cout << NCR( 10, 7 ) << endl;
for (auto& it : primeFactors( 120 ))for (long long i = 0;i < it.second;i++)cout << it.first << ' ';
}
//----------------------------------------------------------------//
// main function//
int main()
{
ios_base::sync_with_stdio( false );
cin.tie( NULL );
cout.tie( NULL );
long long test = 1;
// cin >> test;
while (test--)
{
solve();
}
}