`
haouziwefe
  • 浏览: 128035 次
  • 性别: Icon_minigender_2
  • 来自: 杭州
社区版块
存档分类
最新评论

Problem16

阅读更多

   
package com.shui.mu.yao.io.algorithm;
/**
 * 
 * @author shuimuqinghua77 @date 2012-12-02
 *
 */

public class Problem16 {
	public static void main(String[] args) throws Exception {

		
		byte[] seed=new byte[]{2};/**如果是{1,0,2,4}*/
		seed=getDigit(seed);/**那么转化后得到{4,2,0,1}便于乘法*/
		byte[] result=new byte[]{1};
		for(int i=0;i<1000;i++){
			result = multiply(seed, result);
		}
		int sum=0;
		for(int i=0;i<result.length;i++){
			sum+=result[i];
		}
		System.out.println(sum);
		
	}

	private static byte[] multiply(byte[] multiplicand/**被乘数**/, byte[] multiplier) throws Exception {
		if(multiplicand.length==0||multiplier.length==0)
		{
			throw new Exception("被乘数/乘数为空!!!");
		}
		if(multiplicand.length<multiplier.length){
			byte[] temp=multiplier;
			multiplier=multiplicand;
			multiplicand=temp;
		}
		byte[] result=new byte[multiplicand.length+multiplier.length];
		for(int i=0;i<multiplier.length;i++){
			for(int j=0;j<multiplicand.length;j++){
				result[i+j]+=(byte) (multiplier[i] * multiplicand[j]);
			}
			/**[29]->[9][2]进位**/
			carry(result,1+multiplicand.length,i);
		}
		if(result[result.length-1]==0){
			byte[] resultDest=new byte[result.length-1];
			System.arraycopy(result, 0, resultDest, 0, result.length-1);
			return resultDest;
		}
		
		return result;
	}

	private static void carry(byte[] result,int length,int base) {
		for(int i=base;i<length+base;i++){
			byte decade=(byte) (result[i]/10);
			if(decade>=1){
				result[i+1]+=decade;
				result[i]=(byte) (result[i]%10);
			}
		}
		
	}

	private static byte[] getDigit(byte[] original) {
		byte[] render = new byte[original.length];
		for (int i = 0; i < original.length; i++) {
			render[original.length - 1 - i] = original[i];
		}
		return render;
	}

}

 
0
0
分享到:
评论

相关推荐

    计算机网络第六版答案

    16. The delay components are processing delays, transmission delays, propagation delays, and queuing delays. All of these delays are fixed, except for the queuing delays, which are variable. 17. a) ...

    MySQL数据库考试试题.docx

    16. 子查询:嵌套查询语句(Problem 16) 子查询是指嵌套在另一个查询语句中的查询语句。 17. 插入数据:INSERT 语句(Problem 17) INSERT 语句用于将数据插入到表中。 18. 正则表达式过滤:REGEXP 操作符...

    fundamental of electric circuits

    - **旋转变压器电路**(Problem 16.69): 讨论了旋转变压器的工作原理。 - **计算允许的AM广播频段内的电台数量**(Problem 18.63): 探讨了频谱管理的相关技术。 - **语音信号——奈奎斯特速率**(Problem 18.65): 讨论...

    Computer-Based.Problem.Solving.Process

    Chapter 16. Software Tools for Correct Program Development Part 5 Computer Operation by Problem Solving Process Chapter 17. Using First Computers to Solve Problems Chapter 18. Batch Operating System ...

    AIX 6 System Administration II: Problem Determination (Course code AU16)

    AIX 6 System Administration II: Problem Determination (Course code AU16) Student Exercises with hints 自测练习题

    pattern classification chapter3 answer

    ### Problem 16 #### Part (a) This problem deals with matrix algebra, specifically the inverse of a sum of matrices. Given nonsingular matrices \( A \) and \( B \) of the same order, the equation: \...

    Inverse Problem Theory and Methods for Model Parameter Estimation

    **观测数据**:六个地震站记录了地震波到达的时间,这些地震站位于矩形网格上,坐标分别为:(3km, 15km),(3km, 16km),(4km, 15km),(4km, 16km),(5km, 15km),(5km, 16km)。地震波到达时间的观测值为:3.12秒,...

    Artificial Intelligence and Problem Solving

    16 Random Walks on Graphs & Monte Carlo Methods......Page 298 TheOreTicAL APPLicATiOns......Page 301 random Walks on Graphs......Page 303 mArkOv chAins AnD mOnTe cArLO meThODs......Page 306 references...

    Prime Ring Problem 深度探索

    int M, g, a[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, ag[20], c[20]; ``` - 初始化数组`a`,用于存储可能填入环中的数字。 - `ag`数组用于标记数字是否已被使用。 - `c`...

    Problem Solving with C++

    #### 第16章:STL异常类(p.917) 标准模板库(STL)是C++的一个重要组成部分,提供了大量高效的数据结构和算法。本节讨论了STL中用于处理错误情况的异常类。 - **异常**:表示程序执行过程中发生的非正常事件。 - ...

    Problem Solving with C++ (7th edition)

    #### Chapter 16: Standard Template Library (STL) This chapter covers the Standard Template Library (STL), a powerful set of C++ libraries: - **STL Containers**: Explanation of STL containers, such ...

    C++.Programming.From.Problem.Analysis.to.Program.Design.7th.Edition

    Chapter 16. Searching and Sorting. Chapter 17. Linked Lists. Chapter 18. Stacks and Queues. Appendix A. Reserved Words. Appendix B. Operator Precedence. Appendix C. Character Sets. Appendix D. ...

    Problem Solving in Data Structures & Algorithms Using Java

    CHAPTER 16: BRUTE FORCE ALGORITHM CHAPTER 17: GREEDY ALGORITHM CHAPTER 18: DIVIDE-AND-CONQUER, DECREASE-AND-CONQUER CHAPTER 19: DYNAMIC PROGRAMMING CHAPTER 20: BACKTRACKING AND BRANCH-AND-BOUND ...

    Problem-Solving-with-C++-9th

    #### 第16章:标准模板库异常处理 - **STL 异常类**:探讨了如何使用STL提供的异常处理机制来处理运行时错误。 #### 第17章:模板编程问题 - **编译带有模板的程序**:讨论了模板编程中常见的一些编译问题及解决...

    computer network 5th andre problem solutions-CSDN下载.2018_03_16

    computer network 5th andre problem solutions

    C经典算法之约瑟夫问题(Josephus Problem)

    据说着名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39...然而Josephus 和他的朋友并不想遵从,Josephus要他的朋友先假装遵从,他将朋友与自己安排在第16个与第31个位置,于是逃过了这场死亡游戏。

    C++ Programming: From Problem Analysis to Program Design, 8th Edition

    C++ Programming: From Problem Analysis to Program Design By 作者: D. S. Malik ISBN-10 书号: 1337102083 ISBN-13 书号: 9781337102087 Edition 版本: 8 出版日期: 2017-02-13 pages 页数: 1491 Contents ...

    problem solving with c++ 9th 源码

    而进阶学习者则可通过"Chapter13"和"Chapter16"学习到面向对象编程中的核心概念,例如对象和类的构建、继承、多态性等。 "readme.txt"文件在源码学习中同样扮演着重要角色,它通常会包含编译源码时所需的重要信息,...

Global site tag (gtag.js) - Google Analytics