# Write 199319989756262759279209 = 5x + y, where x and y are integers

$\frac{199319989756262759279209}{5}$ = $3.9864\times 10^{22}$ according to Mathematica, but I would like to see this number exactly in decimal form (not in scientific notation). I'm attempting to use the Euclidean Algorithm and Extended Euclidean algorithm to get a final result, and precision and accuracy both are very much needed. This number truncated would give me x and then y is simply the difference of that large number and 5 x. Unless there's an easier way to do the Euclidean algorithm in Mathematica as well that'd be nice.

-
but I would like to see this number exactly in decimal form (not in scientific notation) You can use AccountingForm? n1 = 199319989756262759279209; AccountingForm[N[n1/5, 30], {30, 29}] gives 39863997951252551855841.8000000 (just remember, this is only a wrapper. –  Nasser Oct 15 '13 at 5:12
Perfect. Thanks! –  Adam Staples Oct 15 '13 at 5:22
@m_goldberg ah I was writing that in an answer when you commented. I think it is good to have an "official" answer though. –  Jacob Akkerboom Oct 15 '13 at 11:07
I overlooked this function for a long time and now suddenly I saw it because it was an option for the autocomplete. I have very often used Mod and Quotient together, being a little frustrated that basically the same computation was being done twice. I learned something today :) –  Jacob Akkerboom Oct 15 '13 at 11:10
Though I guess finding the remainder by simply subtracting the quotient from the original number is not inefficient at all. –  Jacob Akkerboom Oct 15 '13 at 11:15

My remarks are too long for a comment, so I'll place them here.

The title of the OP's entry, namely

Write 199319989756262759279209 = 5x + y, where x and y are integers

is not the same as the question in the body, which asks for an exact decimal representation of

199319989756262759279209 / 5

Regarding the first question, there are integers, x, y, that make 199319989756262759279209 = 5x + y true. This will be true for any integer divisor, not just 5. It follows from the division identity (or division algorithm): given positive integers A, B, there exist non-negative integers Q, R, where R < B, such that A = BQ + R.

Regarding the second question, if we accept a convention, such as a vinculum or ellipsis, for expressing the repeating "tail" of a decimal number, then we can express any fraction exactly as a decimal number. In the worst case scenario, the magnitude of the "non-integer part" of the quotient may require as many as B-1 places, so the decimal expression is always finite, given that the divisor, B, is finite. (The decimal expression with vinculum stands for a non-terminating decimal, however. The case of a repeating zero is dealt with inconsistently.)

-

To find the x and y, we can simply do

{x,y} = QuotientRemainder[199319989756262759279209, 5]


{39863997951252551855841, 4}

The Euclidean algorithm seems like overkill for this case. The operations needed to calculate this have been well optimized and your computer probably has hardware to do such divisions. See wiki:division algorithm for a glimpse of what algorithms are actually used.

Restorable numbers

In reply to comments by DavidCarraher below, I have to add the warning that just storing the x and y is not enough information to restore the result of the fraction. You also need to store the number you divided by. Here are two solutions

quotientRepresentation[num_, base_] :=
{QuotientRemainder[num, base],
base}

quotientFracRepresentation[num_,
base_] :=
{#1, #2/base} & @@ QuotientRemainder[num, base]


We then have

quotientRepresentation[199319989756262759279209, 5]


{{39863997951252551855841, 4}, 5}

and

quotientFracRepresentation[199319989756262759279209, 5]


{39863997951252551855841, 4/5}

Note that it is possible that information about the original number is lost when using quotientFracRepresentation. The remainder is not divisible by the "base", but they may have a common divisor.

To solve this, we can useHoldForm like this

quotientFracHoldFormRepresentation[num_, base_] :=
Function[Null, {#1, HoldForm[Rational[#2, base]]}, HoldAll] @@
QuotientRemainder[num, base]


Examples

quotientFracBoxRepresentation[10, 4]


{2,2/4}

quotientFracHoldFormRepresentation[199319989756262759279210, 4]


{49829997439065689819802,2/4}

Full emphasis on notation

We can also take this all the way I suppose

quotientHoldFormRepresentation[num_, base_] :=

Function[Null, HoldForm@Plus[#1, Rational[#2, base]], HoldAll] @@
QuotientRemainder[num, base]


Example

quotientHoldFormRepresentation[199319989756262759279210, 4]


49829997439065689819802+2/4

quotientHoldFormRepresentation[199319989756262759279210, 4]//FullForm


HoldForm[Plus[49829997439065689819802,Rational[2,4]]]

Now, to retrieve the result of division (for Mathematica to work with), simply do

quotientHoldFormRepresentation[199319989756262759279210,
4] // ReleaseHold


99659994878131379639605/2

-
Also, we should remember that in Mathematica. we can write {x, y} = QuotientRemainder[199319989756262759279209, 5] –  m_goldberg Oct 15 '13 at 11:11
Careful. The quotient plus remainder does not uniquely determine a number. Consider this: QuotientRemainder[9,4] = {2,1}. QuotientRemainder[15,7] = {2,1}. But 9/4 does not equal 15/7. We might alternatively say that the QuotientRemainder function is a one-to-many mapping and hence not invertible. –  David Carraher Oct 15 '13 at 11:16
@DavidCarraher I do not think the OP asked for this. From the notation 39863997951252551855841.8000000 the original number can also not be reconstructed, unless of course you know we have divided by 5 (which is also enough information to reconstruct the number from the quotient and the remainder). –  Jacob Akkerboom Oct 15 '13 at 11:22
I was referring to your answer, which is not a useful representation of the rational number expressed through the given fraction. (Btw, the original number can be reconstructed from the decimal if it is made clear, typically by a vinculum or an ellipsis, that the zero repeats ad infinitum.) –  David Carraher Oct 15 '13 at 11:39
@DavidCarraher ahh, I see what you mean now. Indeed it is a pitfall to think that the rational number could be reproduced from this, good point. I will edit –  Jacob Akkerboom Oct 15 '13 at 11:48