题意:输出n的阶层最后一个非0数。

题解:可以把5和2的个数算出来,每次把5和2都除掉,最后乘上比5多出来的2。我的解法是,每次把尾巴的0去掉,并且保留3位,算到最后取尾数就可以了。、

/*
TASK:fact4
LANG:C++
*/
#include<cstdio>
#include<algorithm>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std;
int main(){
    freopen("fact4.in","r",stdin);
    freopen("fact4.out","w",stdout);
    int n,ans=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        ans*=i;
        while(ans%10==0)ans/=10;
        ans%=1000;
    }
    printf("%d\n",ans%10);
    return 0;
}

 

  

相关文章:

  • 2021-10-07
  • 2021-12-19
  • 2022-02-27
  • 2021-09-07
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-21
猜你喜欢
  • 2022-12-23
  • 2021-08-08
  • 2021-06-16
  • 2021-08-27
  • 2022-12-23
  • 2021-07-21
  • 2021-11-20
相关资源
相似解决方案