Skip to content

Instantly share code, notes, and snippets.

@sadmiko
Last active June 29, 2018 08:12
Show Gist options
  • Save sadmiko/68ac4167533877e87350c9e7be6c004a to your computer and use it in GitHub Desktop.
Save sadmiko/68ac4167533877e87350c9e7be6c004a to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1000000007;
ll facctoria(ll k){
ll mol=1;
for (ll i=1;i<=k;++i)
{
mol*=i;
mol%=mod;
}
return mol;
}
int main(){
ll n,m;cin>>n>>m;
ll N=facctoria(n)%mod;
ll M=facctoria(m)%mod;
if(abs(n-m)==0){
cout<<(2*N*M)%mod<<endl;
}else if(abs(n-m)==1){
cout<<(N*M)%mod<<endl;
}else{
cout<<0<<endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment