杭电1066-N!的最后一个非零数字

package cn.edu.bupt.hd1069;
import java.util.Scanner;

/**
 * Created by Administrator on 2014/11/23. 
 * <span style="color:#ff6666;">WA 原因未知,思路是对的,自测是对的</span>
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        while(scan.hasNext()){
            int n=scan.nextInt();
            System.out.println(work(n));
        }

    }
    public static int[]arr={6,6,2,6,4,4,4,8,4,6};
    public static int[]arr1={6,8,4,2};
    public static int getIndex(long t){
        if(t==6) return 0;
        if(t==8) return 1;
        if(t==4) return 2;
        if(t==2) return 3;
        return -1;
    }
    public static long work(int a){
        if(a==0||a==1) return 1;
        int t=arr[(a%10)];
        t=arr1[(getIndex(t)+a/5%4)%4];
        long t1=work(a/5);
        return t*t1%10;
    }
}

你可能感兴趣的:(OJ)