#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll counter(int n)
{
ll d[n+1], i;
d[0] = 1;
d[1] = 0;
d[2] = 1;
for(i=3;i<=n;i++)
{
d[i] = (i-1) * (d[i-1] + d[i-2]);
}
return d[n];
}
int main()
{
int n;
cout << "Enter A Number :: ";
cin >> n;
ll Derangement_Number = counter(n);
cout << "\n" << n << " Element Derangement Number is :: " << Derangement_Number << "\n";
return 0;
}
#define ll long long int
using namespace std;
ll counter(int n)
{
ll d[n+1], i;
d[0] = 1;
d[1] = 0;
d[2] = 1;
for(i=3;i<=n;i++)
{
d[i] = (i-1) * (d[i-1] + d[i-2]);
}
return d[n];
}
int main()
{
int n;
cout << "Enter A Number :: ";
cin >> n;
ll Derangement_Number = counter(n);
cout << "\n" << n << " Element Derangement Number is :: " << Derangement_Number << "\n";
return 0;
}
Comments
Post a Comment