• 10000阶乘


    public class SuperFactories {
    	public static int lastWithUnZero = 3;// 便捷的输出测试,从几个回。为了找到一个非零元素迄今
    
    	public static void main(String[] args) {
    		int[] factories_10000 = new int[35660];// 用数组装下阶乘的每一位
    		// 5的阶乘为120
    		factories_10000[2] = 1;
    		factories_10000[1] = 2;
    		// 从6的阶乘開始
    		for (int i = 6; i <= 10000; i++) {// 10000的阶乘
    			// n! = n*(n-1)!;阶乘运算
    			for (int j = 0; j <= lastWithUnZero; j++) {//
    				factories_10000[j] *= i;
    			}
    			// 进位
    			for (int j = 0; j <= lastWithUnZero; j++) {//
    				if (factories_10000[j] > 9) {
    					factories_10000[j + 1] += factories_10000[j] / 10;
    					factories_10000[j] %= 10;
    				}
    			}
    			if (factories_10000[lastWithUnZero + 1] > 9) {
    				int temp = lastWithUnZero + 1;
    				while (factories_10000[temp] > 9) {
    					factories_10000[temp +1] += factories_10000[temp] / 10;
    					factories_10000[temp++] %= 10;
    				}
    			}
    			// lastWithUnZero 从后面数。找到一个非零元素为止
    			for (int j = factories_10000.length - 1; j > 0; j--) {
    				if (factories_10000[j] != 0) {
    					lastWithUnZero = j;
    					break;
    				}
    			}
    		}
    		for (int i = lastWithUnZero; i >= 0; i--) {
    			if(i%100==0){
    				System.out.println();
    			}
    			System.out.print(factories_10000[i]);
    		}
    		System.out.println("
    -----------" + lastWithUnZero + "++++++++++"
    				+ factories_10000[lastWithUnZero]);
    	}
    
    }
    

    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    kubernetes架构部署
    GitLab+Jenkins+Ansible
    python之字典方法
    Python之列表方法
    python之字符串方法
    Python编写从ZabbixAPI获取信息
    Django基础
    扫描某个包下所有的类,输出所有使用了特定注解的类的注解值
    日志切面和统一异常处理
    Mybatis动态排序问题
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4831277.html
Copyright © 2020-2023  润新知