1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Project Euler】#001

Posted at

1問目です!

問題

10以下の自然数のうち、3または5の倍数をすべて列挙すると、3、5、6、9となる。これらの倍数の合計は23である。  
1000以下の3または5の倍数の和を求めよ。

他媒体とかでも似たような問題、よく見ますね。

わたしの回答

func main() {

	sum := 0
	for i := 0; i < 1000; i++ {
		if i%3 == 0 || i%5 == 0 {
			sum += i
		}
	}
	fmt.Println(sum)
}

GPT-4oの回答

func main() {
	sum := 0
	for i := 1; i < 1000; i++ {
		if i%3 == 0 || i%5 == 0 {
			sum += i
		}
	}
	fmt.Println(sum)
}

Gemini2.5 Flashの回答

func main() {
	sum := 0
	for i := 1; i < 1000; i++ {
		if i%3 == 0 || i%5 == 0 {
			sum += i
		}
	}
	fmt.Println(sum)
}

感想

どう解いたとしても、答え似てくるよなぁと思いました。

久々にAIのサジェストなしで書いたから、手が止まる感じが久々な感覚でした。
ちょっと頭のキレも弱ってる感じがしました...。

でもやってみると楽しいですね!同僚も巻き込んでいっしょにやれてるので楽しさ倍増です!!

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?