设为首页 加入收藏

TOP

最后一个非零数字(POJ 1604、POJ 1150、POJ 3406)(三)
2019-06-11 12:08:21 】 浏览:339
Tags:最后 一个 数字 POJ 1604 1150 3406
%5==0)

              {

                     cnt5++;

                     t=t/5;

              }

        table[0][i]=table[0][i-1]+cnt2;  // 因子2的个数

              table[2][i]=table[2][i-1]+cnt5;  // 因子5的个数

              table[1][i]=table[1][i-1];       // 末位数字为3的个数

              table[3][i]=table[3][i-1];       // 末位数字为7的个数

              table[4][i]=table[4][i-1];       // 末位数字为9的个数

              if (t%10!=1)

                 table[(t%10-1)/2][i]++;

       }    

       while (cin>>n)

       {

        cnt2=table[0][n]-table[2][n];

              if (cnt2==0)

                     cnt2 = 1;

              else

                     cnt2=last[0][cnt2%4];

              cnt3=last[1][table[1][n]%4];

              cnt7=last[2][table[3][n]%4];

              cnt9=last[3][table[4][n]%4];

        printf("%5d -> %d\n", n, cnt2 * cnt3 * cnt7 * cnt9 % 10);

       }

       return 0;

}

  •  排列数P(n,m)的最后一个非0数字

【例2】The Last Non-zero Digit (POJ 1150)

Description

In this problem you will be given two decimal integer number N, M. You will have to find the last non-zero digit of the P(N,M).This means no of permutations of N things taking M at a time.

Input

The input contains several lines of input. Each line of the input file contains two integers N (0 <= N<= 20000000), M (0 <= M <= N).

Output

For each line of the input you should output a single digit, which is the last non-zero digit of P(N,M). For example, if P(N,M) is 720 then the last non-zero digit is 2. So in this case your output should be 2.

Sample

首页 上一页 1 2 3 4 5 6 7 下一页 尾页 3/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Example: Getting WMI Data from .. 下一篇POJ中和质数相关的三个例题(POJ ..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目