比赛描述
输入
仅一行包含一个正整数N。
输出
单独一行包含一个整数表示最右边的非零位的值。
样例输入
12
样例输出
6
提示
题目来源
NUAA_缪荣
#include<iostream> using namespace std; int GetRightestNoZeroDigitA(int n){ int m = 1, c = 0, i; int cr[] = { 1, 3, 4, 2 }; int rr[] = { 1, 6, 2, 8, 4 }; while( n > 1){ if ( 2 == (i = n % 5) ) m <<= 1; else if ( 4 == i ) m <<= 2; c += n /= 5; } if ( c & 1 ) return rr[ ( cr[ c % 4 ] * 4 * m ) % 5 ]; return rr[ ( cr[ c % 4 ] * m ) % 5 ]; } int main(){ int N; cin>>N; cout<<GetRightestNoZeroDigitA(N)<<endl; } /*Time Limit Exceed at Test 7 #include<stdio.h> #include<stdlib.h> int main() { int n,i,o,k=0,l=0,m=1,r,f; scanf("%d",&n); if(n==1){printf("1\n");exit(0);} for(i=1;i<=n;i++) { o=i; l=0; while(o%2==0) { o=o/2; k=k+1; } while(o%5==0) { o=o/5; l=l+1; } k=k%4-l%4; if(k<0)k=k+4; m=(m*o)%10; } switch(k) { case 0:r=6;break; case 1:r=2;break; case 2:r=4;break; case 3:r=8;break; } f=(m*r)%10; printf("%d\n",f); } */ /*WA4 # include<iostream> using namespace std; int main() { int nNum,sum,i,loop; while(cin>>nNum) { sum=1; for(i=nNum;i>=1;i--) { sum*=i; loop=sum/10; while(loop*10==sum)//消0 { sum/=10; loop=sum/10; } if(sum>=100000)//保存末尾5位数字即可 sum%=100000; } cout<<sum%10<<endl; } return 0; } */ /*WA3 #include <stdio.h> int main(){ int num, p=1; scanf("%d",&num); while(num){ p*=num; while(p%10==0) p/=10; p%=10; num--; } printf("%d\n",p); return 0; } */ /*WA2 #include<stdio.h> int main(){ int N,i,result,temp; scanf("%d",&N); for(result=i=1;i<=N;i++){ temp = i; while(temp%100==0){ temp /= 100; } temp %= 100; result *=temp; while(result%100==0){ result /= 100; } result %= 100; } printf("%d\n",result%10); } */