-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKthFactorial.cpp
More file actions
58 lines (46 loc) · 960 Bytes
/
KthFactorial.cpp
File metadata and controls
58 lines (46 loc) · 960 Bytes
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 <iostream>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
#define MAXN 100
#define sqrtFive sqrt(5)
#define long double ld
ull fn[MAXN];
ull fact(ull n)
{
if( fn[n] == 0 )
{
if( n < 2 )
{
fn[n] = 1;
}else
{
fn[n] = fn[n-1] + fn[n-2];
}
}
return fn[n];
}
ld power(ld x, ull n)
{
if( n == 0 ) return 1;
if( n % 2 ) return x * power(x, n-1);
ld half = power( x, n/2 );
return half * half;
}с
ull fac(ull n)
{
ld multiplier = 1 / sqrtFive;
ld c1 = (1 + sqrtFive) / 2;
ld c2 = (1 - sqrtFive) / 2;
return round(multiplier * (pow(c1, n) - pow(c2, n)) );
}
ull kthfactorial(ull k, ull n)
{
return power(fact(n), k);
//return pow(fac(n), k);
// za dostaty4no golemi stoinosti na n e udobno da izpolzvame fac vmesto fact;
}
int main()
{
return 0;
}