- Joined
- Jul 10, 2007
- Messages
- 6,306
so take integer 123456789123456789 as this
And integer 123456789123 as this
Consider that the two arrays are linked lists with pointers next and prev and a dummy head with boolean head set to true.
How would you do 123456789123456789/123456789123 without any overflow while only using of 32 bit signed integers? Please provide a fast solution that guarantees that there will never ever be overflow no matter what happens ^)^.
You will have to store the remainder in an array (linked list) as well.
Subtracting continuously is not a solution. Guessing a quotient and then subtracting continuously is not a solution either as large numbers will require too many subtractions. Using boolean division is not a solution either >: o.
The integers may be stored using any word size (base) as well. I personally use 32768 =).
May not declare arrays on the fly, may not pass or return pointers unless they are like a pointer to a linked list or a string, may not use strings for storage, may only use single dimensional arrays. Only basic operations allowed are +, -, *, /, =.
Tx ; D
JASS:
set ar[0] = 9
set ar[1] = 8
set ar[2] = 7
set ar[3] = 6
set ar[4] = 5
set ar[5] = 4
set ar[6] = 3
set ar[7] = 2
set ar[8] = 1
set ar[9] = 9
set ar[10] = 8
set ar[11] = 7
set ar[12] = 6
set ar[13] = 5
set ar[14] = 4
set ar[15] = 3
set ar[16] = 2
set ar[17] = 1
And integer 123456789123 as this
JASS:
set ar[18] = 3
set ar[19] = 2
set ar[20] = 1
set ar[21] = 9
set ar[22] = 8
set ar[23] = 7
set ar[24] = 6
set ar[25] = 5
set ar[26] = 4
set ar[27] = 3
set ar[28] = 2
set ar[29] = 1
Consider that the two arrays are linked lists with pointers next and prev and a dummy head with boolean head set to true.
How would you do 123456789123456789/123456789123 without any overflow while only using of 32 bit signed integers? Please provide a fast solution that guarantees that there will never ever be overflow no matter what happens ^)^.
You will have to store the remainder in an array (linked list) as well.
Subtracting continuously is not a solution. Guessing a quotient and then subtracting continuously is not a solution either as large numbers will require too many subtractions. Using boolean division is not a solution either >: o.
The integers may be stored using any word size (base) as well. I personally use 32768 =).
May not declare arrays on the fly, may not pass or return pointers unless they are like a pointer to a linked list or a string, may not use strings for storage, may only use single dimensional arrays. Only basic operations allowed are +, -, *, /, =.
Tx ; D