Project Euler 16 - Help in solving it

go

Solution

Your approach to this problem requires exact integer math up to 1000 bits in size. But you're using `int` which is 32 or 64 bits. math/big.Int can handle such task. I intentionally do not provide a ready made solution using `big.Int` as I assume your goal is to learn by doing it by yourself, which I believe is the intent of Project Euler.

Problem

I'm solving Project Euler problem 16, I've ended up with a code that can logically solve it, but is unable to process as I believe its overflowing or something? I tried int64 in place of int but it just prints 0,0. If i change the power to anything below 30 it works, but above 30 it does not work, Can anyone point out my mistake? I believe its not able to calculate 2^1000. ``` // PE_16 project main.go package main import ( "fmt" ) func power(x, y int) int { var pow int var final int final = 1 for pow = 1; pow <= y; pow++ { final = final * x } return final } func main() { var stp int var sumfdigits int var u, t, h, th, tth, l int stp = power(2,1000) fmt.Println(stp) u = stp / 1 % 10 t = stp / 10 % 10 h = stp / 100 % 10 th = stp / 1000 % 10 tth = stp / 10000 % 10 l = stp / 100000 % 10 sumfdigits = u + t + h + th + tth + l fmt.Println(sumfdigits) } ```

Original source