#include <iostream>
#include <cstdio>
#include <iomanip>
#include <string>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <stack>
#include <stdlib.h>
#include <stdio.h>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define ull unsigned long long
#define uint unsigned int
#define l(x) x<<1
#define r(x) x<<1|1
#define ms(a,b) memset(a,b,sizeof(a))
//#define ms(a,b,c,d) memset(a,b,c*sizeof(d))
using namespace std;
int fact_prime(int n, int x)
{
int res = 0;
while (n)
{
res += n / x;
n /= x;
}
return res;
}
int odd_end_with(int n, int x)
{
if (n == 0) return 0;
return n / 10
+ (n % 10 >= x)
+ odd_end_with(n / 5, x);
}
int end_with(int n, int x)
{
if (n == 0) return 0;
return end_with(n / 2, x)
+ odd_end_with(n, x);
}
int table[4][4] =
{
6, 2, 4, 8,
1, 3, 9, 7,
1, 7, 9, 3,
1, 9, 1, 9,
};
int main()
{
int n, m;
while (~scanf("%d%d", &n, &m))
{
m = n - m;
int two = fact_prime(n, 2) - fact_prime(m, 2);
int five = fact_prime(n, 5) - fact_prime(m, 5);
int three = end_with(n, 3) - end_with(m, 3);
int seven = end_with(n, 7) - end_with(m, 7);
int nine = end_with(n, 9) - end_with(m, 9);
if (two < five)
{
puts("5");
continue;
}
int res = 1;
if (two > five) res *= table[0][(two - five) % 4];
res *= table[1][three % 4];
res *= table[2][seven % 4];
res *= table[3][nine % 4];
res %= 10;
printf("%d\n", res);
}
return 0;
}
poj 1150 (mod)
最新推荐文章于 2025-07-19 23:49:46 发布