这个题,用O(n)真的可以吗?大概是洛谷数据太弱了。
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define LL long long
using namespace std;
int n;
LL ans=1;
LL work(LL x)
{
while(!(x%10)) x/=10;
return x%100000000;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
ans*=work(i);
ans=work(ans);
}
printf("%lld",ans%10);
return 0;
}