1284C. New Year and Permutation - Codeforces Solution C++

  Problem Link : 1284C. New Year and Permutation 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#define ll long long int

ll fact[250001];

int main()
{
	ll n,m;
	cin>>n>>m;

	fact[0]=1;
	fact[1]=1;
	for(ll i=2;i<=n;i++)
		fact[i]=(i*fact[i-1])%m;
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ll curr=(n-i+1)%m;
		curr=(curr*(n-i+1))%m;
		curr=(curr*fact[i])%m;
		curr=(curr*fact[n-i])%m;
		ans=(ans+curr)%m;
	}
	cout<<ans;

}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!