2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

5と8の和で表すことができない最大の整数を求めてみた

Last updated at Posted at 2019-01-27

Twitterで話題になっていたので適当実装でやってみる

実装

適当

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main () {
	stdin := bufio.NewScanner(os.Stdin)
	
	stdin.Scan()
	input := stdin.Text()
	first, _ := strconv.Atoi(strings.TrimSpace(input))

	stdin.Scan()
	input = stdin.Text()
	second, _ := strconv.Atoi(strings.TrimSpace(input))

	for solve := 0;; solve++ {
		flag := false
		for i := 0;; i++ {
			tmp := solve - first * i
			if (tmp < 0) {
				break
			}
			for j := 0;; j++ {
				tmp := tmp - second * j
				if tmp == 0 {
					flag = true
					break
				} else if tmp < 0 {
					break
				}
			}

		}
		if !flag {
			fmt.Println(solve)
		}
	}
}

出力結果

1
2
3
4
6
7
9
11
12
14
17
19
22
27

ということで27が最高っぽい
ちなみに8と7だと41が最高だった
数式で表せるのかな?

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?