【算法】程序猿不写代码是不对的76
来源:互联网 发布:js调用mvc方法 编辑:程序博客网 时间:2024/05/29 18:02
package com.kingdz.algorithm.time201707;/** * <pre> * 阶乘最后一个非零位 * * http://judgecode.com/problems/1008 * * Given a non-negative integer n, calculate the last non-zero digit of n's factorial, namely n!. 0! = 1! = 1, 2!= 2, 3!= 6…etc. * * Input:A non-negative integer n no larger than 1000000. * * </pre> * * @author kingdz * */public class Algo03 { public static void main(String[] args) { int n = 1000000; int result = calculateLast(n); System.out.println("the last is:" + result); } private static int calculateLast(int n) { if (n == 0 || n == 1) { return 1; } int result = 1; for (int i = 1; i <= n; i++) { result = result * i; while (("" + result).endsWith("0")) { result = result / 10; } result = result % 1000; } return result % 10; }}
阅读全文
0 0
- 【算法】程序猿不写代码是不对的76
- 【算法】程序猿不写代码是不对的1
- 【算法】程序猿不写代码是不对的2
- 【算法】程序猿不写代码是不对的3
- 【算法】程序猿不写代码是不对的4
- 【算法】程序猿不写代码是不对的5
- 【算法】程序猿不写代码是不对的6
- 【算法】程序猿不写代码是不对的7
- 【算法】程序猿不写代码是不对的8
- 【算法】程序猿不写代码是不对的9
- 【算法】程序猿不写代码是不对的10
- 【算法】程序猿不写代码是不对的11
- 【算法】程序猿不写代码是不对的12
- 【算法】程序猿不写代码是不对的13
- 【算法】程序猿不写代码是不对的14
- 【算法】程序猿不写代码是不对的15
- 【算法】程序猿不写代码是不对的16
- 【算法】程序猿不写代码是不对的17
- gulp构建工具学习(day1)
- AngularJS复制的几种方法
- 算法基础:Stack堆栈的应用
- Flink学习笔记 --- Intellij自动导入
- python基础 循环结构程序设计(上)
- 【算法】程序猿不写代码是不对的76
- 算法-floyd判环(圈)算法
- 如何搭建esp32的arduono开发环境
- CSS样式的权值——确定最终起作用的CSS样式
- linux下安装boost库环境
- MSP430F1时基模块应用范例
- jquery的==与===的区别讲解
- ubuntu-用户名密码修改、mail的使用和软件卸载问题
- Django-使用MySQL数据库