hdu 3037
poj 3406 2249
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int n,m;
const int maxsize=1000100;
const int mod=10;
bool v[maxsize];
int p[maxsize],a[maxsize];
int nump;
void solve(int n,int x)
{
int i=1;
while(p[i]<=n)
{
int y=n;
while(y!=0)
{
if(x==1)a[p[i]]+=y/p[i];else a[p[i]]-=y/p[i];
y=y/p[i];
}
i++;
}
}
int pow(int a,int b)
{
if(b==0) return 1;
int ans=pow(a,b/2)%mod;
if(b%2==0)return (ans*ans)%mod;
else return ((ans*ans)*(a%mod))%mod;
}
int main()
{
memset(v,true,sizeof(v));
for(int i=2;i*i<=maxsize;i++)
if(v[i])
for(int j=i*i;j<=maxsize;j+=i)
v[j]=false;
nump=0;
for(int i=2;i<=maxsize;i++)
if(v[i])
{
nump++;
p[nump]=i;
}
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=1;i<=n;i++)
a[i]=0;
solve(n,1);
solve(m,-1);
solve(n-m,-1);
int ans=1;
int t=min(a[2],a[5]);
a[2]-=t;
a[5]-=t;
for(int i=1;p[i]<=n;i++)
if(a[p[i]]>0)
ans=(ans*pow(p[i],a[p[i]]))%mod;
printf("%d\n",ans);
}
return 0;
}