LoginSignup
0
0

More than 1 year has passed since last update.

数学オリンピックの問題をC#で

Last updated at Posted at 2023-03-30

すみません。つぎのYoutube動画で紹介されていた問題で、こたえについてもJAVAでかかれていたものを、c#にしただけです。

問題は、
$ab+c=2020$, $a+bc=2021$
を満たす正の整数$a$,$b$,$c$求めてねってもの。

c#で書いたコードは以下の通り.
整数型は、キャレット(^)使えないっていわれた。

for(int i = 1; i <= 2021; i++){
    for(int ii = 1; ii <= 2021; ii++){
        if(i+2020*ii-i*ii*ii==2021)
        {
            Console.Write("a=");
            Console.Write(i.ToString());
            Console.Write(", b=");
            Console.Write(ii.ToString());
            Console.Write(", c=");
            Console.WriteLine((2020-i*ii).ToString());
         }
        }
  
}

こたえは、$a = 673$, $b=2$, $c=674$....

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