AcWing每日一题--阶乘
作者:互联网
https://www.acwing.com/problem/content/1383/
1 #include<iostream> 2 using namespace std; 3 int main(void){ 4 int n; 5 cin>>n; 6 int res=1; 7 int d2=0,d5=0; 8 for(int i=1;i<=n;i++){ 9 int x=i; 10 while(x%2==0){ 11 x/=2; 12 d2++; 13 } 14 while(x%5==0){ 15 x/=5; 16 d5++; 17 } 18 res=(res*(x%10))%10; 19 } 20 int k=min(d2,d5); 21 for(int i=0;i<d2-k;i++) res=res*2%10; 22 for(int i=0;i<d5-k;i++) res=res*5%10; 23 cout<<res; 24 return 0; 25 }
标签:www,--,res,int,阶乘,d5,d2,AcWing 来源: https://www.cnblogs.com/greenofyu/p/14328653.html