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 7086149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:30:50+00:00 2026-05-28T07:30:50+00:00

I am searching for an algorithm that allow me to compute (2^n)%d with n

  • 0

I am searching for an algorithm that allow me to compute (2^n)%d with n and d 32 or 64 bits integers.

The problem is that it’s impossible to store 2^n in memory even with multiprecision libraries, but maybe there exist a trick to compute (2^n)%d only using 32 or 64 bits integers.

Thank you very much.

  • 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-28T07:30:51+00:00Added an answer on May 28, 2026 at 7:30 am

    Take a look at the Modular Exponentiation algorithm.

    The idea is not to compute 2^n. Instead, you reduce modulus d multiple times while you are powering up. That keeps the number small.

    Combine the method with Exponentiation by Squaring, and you can compute (2^n)%d in only O(log(n)) steps.

    Here’s a small example: 2^130 % 123 = 40

    2^1   % 123 = 2
    2^2   % 123 = 2^2      % 123    = 4
    2^4   % 123 = 4^2      % 123    = 16
    2^8   % 123 = 16^2     % 123    = 10
    2^16  % 123 = 10^2     % 123    = 100
    2^32  % 123 = 100^2    % 123    = 37
    2^65  % 123 = 37^2 * 2 % 123    = 32
    2^130 % 123 = 32^2     % 123    = 40
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is known that google has best searching & indexing algorithm. The also have
I'm searching for an implementations of the Damerau–Levenshtein algorithm for PHP, but it seems
I am using this python library that implements the Aho-Corasick string searching algorithm that
I'm searching for an algorithm that generates all permutations of fixed-length partitions of an
I need to solve a computational problem that boils down to searching for reciprocally-nearest
Is there a rgaph searching algorithm that searches through a graph (from point a
is there an algorithm that is faster than binary search, for searching in sorted
I'm searching for an algorithm to compress small text strings: 50-1000 bytes (i.e. URLs).
I'm searching for an algorithm to calculate the average distance between a point and
I'm searching for an algorithm for Digit summing. Let me outline the basic principle:

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.