Constant FactorialLimit = 365; % Target number to solve, 365! Array digit[1:Limit] of integer; % The big number. Integer carry,d; % Assistants during multiplication. Integer last,i; % Indices to the big number's digits. Array text[1:Limit] of character; % Scratchpad for the output. Constant tdigit[0:9] of character = ["0","1","2","3","4","5","6","7","8","9"]; BEGIN digit:=0; % Clear the whole array. digit[1]:=1; % The big number starts with 1, last:=1; % Its highest-order digit is number 1. for n:=1 to FactorialLimit do % Step through producing 1!, 2!, 3!, 4!, etc. carry:=0; % Start a multiply by n. for i:=1 to last do % Step along every digit. d:=digit[i]*n + carry; % The classic multiply. digit[i]:=d mod Base; % The low-order digit of the result. carry:=d div Base; % The carry to the next digit. next i; while carry > 0 % Store the carry in the big number. if last >= Limit then croak("Overflow!"); % If possible! last:=last + 1; % One more digit. digit[last]:=carry mod Base; % Placed. carry:=carry div Base; % The carry reduced. Wend % With n > Base, maybe > 1 digit extra. text:=" "; % Now prepare the output. for i:=1 to last do % Translate from binary to text. text[Limit - i + 1]:=tdigit[digit[i]]; % Reversing the order. next i; % Arabic numerals put the low order last. Print text," = ",n,"!"; % Print the result! next n; % On to the next factorial up. END; With the example in view, a number of details can be discussed. The most important is the choice of the representation of the big number. In this case, only integer values are required for digits, so an array of fixed-width integers is adequate. It is convenient to have successive elements of the array represent higher powers of the base. The second most important decision is in the choice of the base of arithmetic, here ten. There are many considerations. The scratchpad variable d must be able to hold the result of a single-digit multiply plus the carry from the prior digit's multiply. In base ten, a sixteen-bit integer is certainly adequate as it allows up to 32767. However, this example cheats, in that the value of n is not itself limited to a single digit. This has the consequence that the method will fail for n > 3200 or so. In a more general implementation, n would also use a multi-digit representation. A second consequence of the shortcut is that after the multi-digit multiply has been completed, the last value of carry may need to be carried into multiple higher-order digits, not just one. There is also the issue of printing the result in base ten, for human consideration. Because the base is already ten, the result could be shown simply by printing the successive digits of array digit, but they would appear with the highest-order digit last (so that 123 would appear as "321"). The whole array could be printed in reverse order, but that would present the number with leading zeroes ("00000...000123") which may not be appreciated, so this implementation builds the representation in a space-padded text variable and then prints that. The first few results (with spacing every fifth digit and annotation added here) are: This implementation could make more effective use of the computer's built in arithmetic. A simple escalation would be to use base 100 (with corresponding changes to the translation process for output), or, with sufficiently wide computer variables (such as 32-bit integers) we could use larger bases
750
(500+750)/2 = 625
The number is 750.
The number is 750.
250 less than 500 = 500 - 250 500 - 250 = 250
66.7% 500 = 66.7% of 750
750 It is 250 more than 500 and 250 less than 1000. To find the halfway point (the average), add the two numbers and divide by 2.
Idle should be between 500 to 750 RPM.
Break it down this way: 150% of 500 = (100% of 500)+(50% of 500) = 500 + 250 = 750
3500 - 750 = 2750
750
anywhere between $500 and $750.