Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have very large numbers (million digits).

number = A*10^partlen + B

As of now, I split the numbers by this way:

 TotalLen = IntegerLength[a]; 
 partlen = IntegerPart[TotalLen/2];
 Print[First[Timing[A = IntegerPart[number/(10^partlen )]]]];
 Print[First[Timing[B = Mod[number, 10^partlen ]]]]

And the timings for a 6 million digits number are:



Converting the number to strings and rebuilding the parts is even slower than this.

Is there any faster way?

share|improve this question
You're aware of Mod[]'s partner Quotient[], aren't you? For that matter, have you seen QuotientRemainder[]? – J. M. Nov 24 '12 at 10:32

Per J.M. suggestion, I've got a ten fold increase in speed:

TotalLen = IntegerLength[a]; 

RightLen = Quotient[TotalLen, 2]; 

Print[First[Timing[{A, B} = QuotientRemainder[a, (10^RightLen)]]]];



Although the time decreased but it is yet so large just for pre-processing.

share|improve this answer
You didn't totally take my suggestion. Try RightLen = Quotient[TotalLen, 2]; Also, Mathematica is perfectly capable of parallel assignment: {A, B} = QuotientRemainder[number, 10^RightLen]. – J. M. Nov 24 '12 at 12:27
Quotient[] and QuotientRemainder[] are two different functions, see... – J. M. Nov 24 '12 at 13:11
Oh sorry, I mistyped it – Mohsen Afshin Nov 24 '12 at 13:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.