exponentiation

How do you do *integer* exponentiation in C#?

The built-in Math.Pow() function in .NET raises a double base to a double exponent and returns a double result. What's the best way to do the same with integers? Added: It seems that one can just cast Math.Pow() result to (int), but will this always produce the correct number and no rounding errors? ...

Fast exponentiation when only first k digits are required?

This is actually for a programming contest, but I've tried really hard and haven't got even the faintest clue how to do this. Find the first and last k digits of nm where n and m can be very large ~ 10^9. For the last k digits I implemented modular exponentiation. For the first k I thought of using the binomial theorem upto certain po...

Raising to power in PHP

Well, i need to do some calculations in PHP script. And i have one expression that behaves wrong. echo 10^(-.01); Outputs 10 echo 1 / (10^(.01)); Outputs 0 echo bcpow('10', '-0.01') . '<br/>'; Outputs 1 echo bcdiv('1', bcpow('10', '0.01')); Outputs 1.000.... I'm using bcscale(100) for BCMath calculations. Excel and Wolfram ...

Fastest modular exponentiation in JavaScript

My problem is to compute (g^x) mod p quickly in JavaScript, where ^ is exponentiation, mod is the modulo operation. All inputs are nonnegative integers, x has about 256 bits, and p is a prime number of 2048 bits, and g may have up to 2048 bits. Most of the software I've found that can do this in JavaScript seems to use the JavaScript Bi...

Fast exponentiation: real^real (C++ MinGW, Code::Blocks)

I am writing an application where in a certain block I need to exponentiate reals around 3*500*500 times. When I use the exp(y*log(x)) algorithm, the program noticeably lags. It is significantly faster if I use another algorithm based on playing with data types, but that algorithm isn't very precise, although provides decent results for ...

Problem using map with a list of lists in Haskell

Hi I am using Haskell to solve problem 99 in euler project, where I must find the maximum result from a list of base exponent pairs. I came up with this: prob99 = maximum $ map ((fst)^(snd)) numbers Where the numbers are in the form: numbers = [[519432,525806],[632382,518061],[78864,613712].. Why doesn't this work? Do I need to c...

Fast exponentiation implementation

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 ...

What does the ^ operator do in Java?

What function does the "^" operator serve in Java? When I try this: int a = 5^n; ...it gives me: for n = 5, returns 0 for n = 4, returns 1 for n = 6, returns 3 ...so I guess it doesn't indicate exponentiation. But what is it then? ...

ASP.NET CSV Response, Excel Exponential Format Issue

Hi, In my ASP.NET application, I need to write DataTable as CSV response to the customer. Everything is working fine except a column which has a numbers. Ex: 7002136138603600000 But when I open the CSV in Excel, it is showing in exponential format. Something like this: 7E+18 Could you please let me know what needs to be done in or...

Modular Exponentiation for high numbers in C++

Hello all! So I've been working recently on an implementation of the Miller-Rabin primality test. I am limiting it to a scope of all 32-bit numbers, because this is a just-for-fun project that I am doing to familiarize myself with c++, and I don't want to have to work with anything 64-bits for awhile. An added bonus is that the algori...

Tail-recursive pow() algorithm with memoization?

I'm looking for an algorithm to compute pow() that's tail-recursive and uses memoization to speed up repeated calculations. Performance isn't an issue; this is mostly an intellectual exercise - I spent a train ride coming up with all the different pow() implementations I could, but was unable to come up with one that I was happy with t...

first n digits of an exponentiation

How do i determine the first n digits of an exponentiation (ab). eg: for a = 12, b = 13 & n = 4, the first 4 digits are 1069. ...