Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6243115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:04:45+00:00 2026-05-24T12:04:45+00:00

I’m writing a program and I multiply numbers by 5… For example: var i:integer;

  • 0

I’m writing a program and I multiply numbers by 5… For example:

var
  i:integer;
  k:int64;
begin
  k:=1;
  for i:=1 to 200000000 do
  begin
    k:=5*(k+2);
  end;
  end;
end.

But when I compıle and start my program I get an overflow integer error. How can I solve this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:04:46+00:00Added an answer on May 24, 2026 at 12:04 pm

    @Patrick87 is right; no integer type on a computer can hold such a number.
    @AlexanderMP is also right; you would have to wait for a very long time for this to finish.

    Ignoring all that, I think you’re asking for a way to handle extremely large number that won’t fit in an integer variable.
    I had a similar problem years ago and here’s how I handled it…

    Go back to the basics and calculate the answer the same way you would if you were doing it with pencil and paper. Use string variables to hold the text representation of your numbers and create functions that will add & multiply those strings. You already know the algorithms, you learned it as a kid.

    If your have two functions are MultiplyNumStrings(Str1, Str2) & AddNumStrings(Str1, Str2) you sample code would look similar except that K is now a string and not an int64:

    var
      i : integer;
      k : string;
    begin
      k := '1';
      for i:=1 to 200000000 do
      begin
        k := MultiplyNumStrings('5', AddNumStrings(k, '2'));
      end;
    end;
    

    This function will add two numbers that are represented by their string digits:

    function AddNumStrings (Str1, Str2 : string): string;
    var
      i : integer;
      carryStr : string;
      worker : integer;
      workerStr : string;
    begin
      Result := inttostr (length(Str1));
      Result := '';
      carryStr := '0';
    
      // make numbers the same length
      while length(Str1) < length(Str2) do
        Str1 := '0' + Str1;
    
      while length(Str1) > length(Str2) do
        Str2 := '0' + Str2;
    
      i := 0;
      while i < length(Str1) do
      begin
        worker := strtoint(copy(Str1, length(str1)-i, 1)) +
                  strtoint(copy(Str2, length(str2)-i, 1)) +
                  strtoint (carryStr);
        if worker > 9 then
        begin
          workerStr := inttostr(worker);
          carryStr := copy(workerStr, 1, 1);
          result := copy(workerStr, 2, 1) + result;
        end
        else
        begin
          result := inttostr(worker) + result;
          carryStr := '0';
        end;
    
    
        inc(i);
      end; { while }
      if carryStr <> '0' then
        result := carryStr + result;
    end;
    

    This function will multiply two numbers that are represented by their string digits:

    function MultiplyNumStrings (Str1, Str2 : string): string;
    var
      i, j : integer;
      carryStr : string;
      worker : integer;
      workerStr : string;
      tempResult : string;
    begin
      Result := '';
      carryStr := '0';
      tempResult := '';
    
      // process each digit of str1
      for i := 0 to length(Str1) - 1 do
      begin
        while length(tempResult) < i do
          tempResult := '0' + tempResult;
    
        // process each digit of str2
        for j := 0 to length(Str2) - 1 do
        begin
          worker := (strtoint(copy(Str1, length(str1)-i, 1)) *
                     strtoint(copy(Str2, length(str2)-j, 1))) +
                    strtoint (carryStr);
          if worker > 9 then
          begin
            workerStr := inttostr(worker);
            carryStr := copy(workerStr, 1, 1);
            tempResult := copy(workerStr, 2, 1) + tempResult;
          end
          else
          begin
            tempResult := inttostr(worker) + tempResult;
            carryStr := '0';
          end;
        end; { for }
        if carryStr <> '0' then
          tempResult := carryStr + tempResult;
        carryStr := '0';
    
        result := addNumStrings (tempResult, Result);
        tempResult := '';
      end; { for }
    
      if carryStr <> '0' then
        result := carryStr + result;
    end;
    

    Example: We know the max value for an int64 is 9223372036854775807.
    If we multiply 9223372036854775807 x 9223372036854775807 using the above routine we get 85070591730234615847396907784232501249.

    Pretty cool, huh?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I am writing an app with both english and french support. The app requests
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.