Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Compile me with -std=c++14 or higher
- #include <bits/stdc++.h>
- using namespace std;
- using func_t = std::function <long double (long double)>;
- const long double epsilon = 1e-2;
- auto make_derivative(func_t func) {
- return [func](long double x) -> long double {
- return (func(x + epsilon) - func(x - epsilon)) / (2.0 * epsilon);
- };
- }
- long long factorial(long long n) {
- func_t func = [n](long double x) -> long double {
- return pow(x, n);
- };
- func_t tmp = func;
- for (int i = 0; i < n; ++i) {
- tmp = make_derivative(tmp);
- }
- return (long long)round(tmp(1.0));
- }
- int main() {
- int n;
- cin >> n;
- cout << factorial(n) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement