Could someone please point out a site where I can find an algorithm to efficiently calculate integer exponentiation to large powers using C#?
eg. I want to calculate 2^60000 or 3^12345
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
Unless this is homework, you probably don’t want to roll your own implementation of arbitrary precision exponentiation. Calculating large exponents of the type you describe is complicated – performance aside.
I would recommend using one of the existing arbitrary precision arithmetic libraries, like GMP – most of which have libraries to access them from C#.
F# has support for arbitrary precision arithmetic using the BigInt class (which you can also access from C# if you import the assembly it’s in). However, I don’t know how optimized BigInt exponentiation is.
If you’re simply trying to learn about efficient algorithms for exponentiation, you may want to look into the Square-And-Multiply algorithm for exponentiation.