用String设置的大数及部分算法(java),大数的农夫算法、分治算法等都可以用到(String set with the large number and part of the algorithm (Java), large number of farmers algorithm, divide and conquer algorithm, etc. can be used).doc
文本预览下载声明
用String设置的大数及部分算法(java),大数的农夫算法、分治算法等都可以用到(String set with the large number and part of the algorithm (Java), large number of farmers algorithm, divide and conquer algorithm, etc. can be used)
Using String and int[] to achieve a large integer algorithm
The integration of large integer addition, subtraction (only, multiplication, larger than the subtrahend minuend) multiplied by 2, divided by 2, minus 1, and determine whether the 1 parity judgment method, and toString (show) method with toString (method), 0, 1, 10.
Multiplication and addition, after many tests and modifications, basically do not have any problems, division, because it did not use, so did not write.
Can be used in large numbers algorithm, farmer algorithm, brute force algorithm, and so on.
Public, class, MyBigInt {
Public, static, final, int[], ten = {10};
Public, static, final, int[], zero = {0};
Public, static, final, int[], one = {1};
Int[] myInt;
Public, int[], getMyInt () {
Return myInt;
}
Public, void, setMyInt (int[], myInt) {
This.myInt = myInt;
}
Public, MyBigInt () {
MyInt = zero;
}
Public MyBigInt (String, a) {
MyInt = new, int[a.length ()];
For (int i = 0; I myInt.length; i++) {
MyInt[i] = Integer.parseInt (String.valueOf (a.charAt (myInt.length)
- I - 1));
}
}
Public, MyBigInt, chengFa (MyBigInt, myBigInt) {
Int[] myIntA = myInt;
Int[] myIntB = myBigInt.getMyInt ();
Int, a, b;
Int s = 0;
Int c = 0;
Int[], TMP, result;
TMP = new, int[myIntA.length + myIntB.length];
Result = new, int[myIntA.length + myIntB.length];
For (int i = 0; I myIntA.length; i++) {
For (int j = 0; J myIntB.length; j++) {
A = myIntA[i];
B = myIntB[j];
S = (a * B);
Tmp[i + j] = s;
}
}
For (int, I = 0, I, tmp.length - 1, i++) {
C = tmp[i] / 10;
Tmp[i] = tmp[i]% 10;
Tmp[i + 1] = tmp[i + 1] + c;
}
For (int i = 0; I tmp.length; i++) {
Result[i] = tmp[i];
}
While (result[result.length - 1] = = 0) {
TMP = new, int[result.length - 1];
For (int i = 0; I tmp.length; i++) {
Tmp[i] = result[i];
}
Result = tmp;
}
MyBigInt, r
显示全部