Problem 1 - 10

# Project Euler Problem 1 - 10

## 親記事

https://qiita.com/wing-tail/items/6c81bc6217c8440186ab

## Problem 1

```Go:Main.go
package main
import (
    "fmt"
)
func main(){
    sum := 0
    for i := 1; i < 1000; i++ {
        if i % 3 != 0 && i % 5 != 0 {
            continue
        }
        sum += i
    }
    fmt.Println(sum)
}
```

## Problem 2

```Go:Main.go
package main
import (
    "fmt"
    "math"
)
func main(){
    before_term := 0
    term := 1
    sum := 0
    for {
        if term > 4 * int(math.Pow(10, 6)) {
            break
        }
        before_term, term = term, before_term + term
        if before_term % 2 == 0 {
            sum += before_term
        }
    }
    fmt.Println(sum)
}
```

## Problem 3

```Go:Main.go
package main
import (
    "fmt"
    "math"
)
func main(){
    input := 600851475143
    max_prime := 1
    max := int(math.Sqrt(float64(input)))
    for i := 2; i < max; i++ {
        for {
            if input % i != 0 {
                break
            }
            input = int(input / i)
            if max_prime != i {
                max_prime = i
            }
        }
        if input == 1 {
            break
        }
    }
    fmt.Println(max_prime)
}
```

## Problem 4

```Go:Main.go
package main
import (
    "fmt"
)
func main(){
    max := 999
    min := 99
    ret := 0
    for i := max; i > min; i-- {
        if i * max < ret + 1 {
            break
        }
        for j := max; j > min; j-- {
            if i * j < ret + 1 {
                break
            }
            tmp_int := i * j
            reverse := 0
            for {
                if tmp_int < 1 {
                    break
                }
                digit := tmp_int % 10
                reverse = digit + reverse * 10
                tmp_int = int(tmp_int / 10)
            }
            if reverse != i * j {
                continue
            }
            ret = i * j
        }
    }
    fmt.Println(ret)
}
```

## Problem 5

```Go:Main.go
package main
import (
    "fmt"
    "math"
)
func main(){
    ret := 1
    for i := 20; i > 1; i-- {
        if ret % i == 0 {
            continue
        }
        tmp_int := i
        for j := 2; j < i + 1; j++ {
            if tmp_int < j {
                break
            }
            count := 0
            for {
                if tmp_int % j != 0 {
                    break
                }
                count += 1
                tmp_int = int(tmp_int / j)
                if ret % j == 0 {
                    ret = int(ret / j)
                }
            }
            if count == 0 {
                continue
            }
            prime := float64(j)
            exp := float64(count)
            ret *= int(math.Pow(prime, exp))
        }
    }
    fmt.Println(ret)
}
```

## Problem 6

```Go:Main.go
package main
import (
    "fmt"
    "math"
)
func main(){
    squr_sum := 0
    sum_squr := 0
    for i := 1; i < 101; i++ {
        squr_sum += i * i
        sum_squr += i
    }
    diff := float64(sum_squr * sum_squr - squr_sum)
    ret := int(math.Abs(diff))
    fmt.Println(ret)
}
```

## Problem 7

```Go:Main.go
package main
import (
    "fmt"
    "math"
)
func main(){
    prime_list := []int{2}
    i := 2
    for {
        i++
        max_prime := prime_list[len(prime_list) - 1]
        for _, prime := range prime_list {
            if i % prime == 0 {
                break
            }
            if prime == max_prime {
                prime_list = append(prime_list, i)
            }
        }
        if len(prime_list) == 1 + int(math.Pow(10, 4)) {
            break
        }
    }
    target_index := len(prime_list) - 1
    fmt.Println(prime_list[target_index])
}
```

## Problem 8

```Go:Main.go
package main
import (
    "fmt"
    "strconv"
)
func main(){
    input := "73167176531330624919225119674426574742355349194934"
    input += "96983520312774506326239578318016984801869478851843"
    input += "85861560789112949495459501737958331952853208805511"
    input += "12540698747158523863050715693290963295227443043557"
    input += "66896648950445244523161731856403098711121722383113"
    input += "62229893423380308135336276614282806444486645238749"
    input += "30358907296290491560440772390713810515859307960866"
    input += "70172427121883998797908792274921901699720888093776"
    input += "65727333001053367881220235421809751254540594752243"
    input += "52584907711670556013604839586446706324415722155397"
    input += "53697817977846174064955149290862569321978468622482"
    input += "83972241375657056057490261407972968652414535100474"
    input += "82166370484403199890008895243450658541227588666881"
    input += "16427171479924442928230863465674813919123162824586"
    input += "17866458359124566529476545682848912883142607690042"
    input += "24219022671055626321111109370544217506941658960408"
    input += "07198403850962455444362981230987879927244284909188"
    input += "84580156166097919133875499200524063689912560717606"
    input += "05886116467109405077541002256983155200055935729725"
    input += "71636269561882670428252483600823257530420752963450"
    runes := []rune(input)
    amount := 13
    ret := 0
    for i := 0; i < len(runes) - amount; i++ {
        multiple := 1
        for j := 0; j < amount; j++ {
            str := string(runes[i + j])
            val, _ := strconv.Atoi(str)
            multiple *= val
        }
        if multiple > ret {
            ret = multiple
        }
    }
    fmt.Println(ret)
}
```

## Problem 9

```Go:Main.go
package main
import (
    "fmt"
    "math"
)
func main(){
    i := 1
    for {
        max := int(math.Pow(10, 3)) - i
        if max < i + 1 {
            break
        }
        squr_i := i * i
        for j := i + 1; j < max - j; j++ {
            if squr_i + j * j != (max - j) * (max - j) {
                continue
            }
            fmt.Println(i * j * (max - j))
            return
        }
        i++
    }
}
```

## Problem 10

```Go:Main.go
package main
import (
    "fmt"
    "math"
)
func main(){
    max := 2 * int(math.Pow(10, 6))
    input_list := make([]bool, max)
    for key, _ := range input_list {
        if key == 0 {
            continue
        }
        input_list[key] = true
    }
    ret := 0
    for key, value := range input_list {
        if value == false {
            continue
        }
        prime := key + 1
        ret += prime
        i := key
        for {
            i += prime
            if i > max - 1 {
                break
            }
            input_list[i] = false
        }
    }
    fmt.Println(ret)
}
```