Fork me on GitHub

P1134 阶乘问题

luogu 传送门

这里写图片描述

这个题,用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;
}
posted @ 2017-09-24 17:48  primes  阅读(92)  评论(0编辑  收藏  举报