【初中数学竞赛题】已知m,n为正整数,且m^2+n^2=2009,求m+n的值。

已知 m m m, n n n为正整数,且 m 2 + n 2 = 2009 m^2+n^2=2009 m2+n2=2009,求 m + n m+n m+n的值。


一、使用因式分解加枚举

① 对2009进行短除

7 | 2009 ‾ 7 | 287 ‾ 41 7 \underbar{|\enspace\enspace2009\enspace} \\ \enspace\enspace 7 \underbar{|\enspace287\enspace}\\ \enspace\enspace\enspace\enspace\enspace 41 \enspace 7|20097|28741

② 整理

2009 = 7 2 × ( a 2 + b 2 ) = 7 2 × a 2 + 7 2 × b 2 = ( 7 a ) 2 + ( 7 b ) 2 2009=7^2×(a^2+b^2)=7^2×a^2+7^2×b^2=(7a)^2 +(7b)^2 2009=72×(a2+b2)=72×a2+72×b2=(7a)2+(7b)2
m = 7 a m=7a m=7a, n = 7 b n=7b n=7b, a 2 + b 2 = 41 a^2+b^2=41 a2+b2=41

③ 根据题目限定范围为正整数进行枚举

a = 1 a=1 a=1, b = ± 40 b=±\sqrt{40} b=±40 (不成立)
a = 2 a=2 a=2, b = ± 37 b=±\sqrt{37} b=±37 (不成立)
a = 3 a=3 a=3, b = ± 32 b=±\sqrt{32} b=±32 (不成立)
a = 4 a=4 a=4, b = ± 25 = ± 5 b=±\sqrt{25}=±5 b=±25 =±5 (成立)
a = 5 a=5 a=5, b = ± 16 = ± 4 b=±\sqrt{16}=±4 b=±16 =±4 (成立)
a = 6 a=6 a=6, b = ± 5 b=±\sqrt{5} b=±5 (不成立)
a = 7 a=7 a=7, b = ± − 8 b=±\sqrt{-8} b=±8 (不成立)

④ 根据枚举结果和题目限定范围为正整数

a = 4 a=4 a=4, b = 5 b=5 b=5 m = 28 m=28 m=28, n = 35 n=35 n=35 m + n = 28 + 35 = 63 m+n=28+35=63 m+n=28+35=63
a = 5 a=5 a=5, b = 4 b=4 b=4 m = 35 m=35 m=35, n = 28 n=28 n=28 m + n = 35 + 28 = 63 m+n=35+28=63 m+n=35+28=63
所以: m + n = 63 m+n=63 m+n=63


二、使用编程进行枚举

public static void Calc()
{
   int max = (int)Math.Ceiling(Math.Sqrt(2009));
   for (int n = 0; n < max; n++)
   {
       for (int m = 0; m < max; m++)
       {
           double v = Math.Pow(n,2) + Math.Pow(m, 2);
           if(v== 2009)
           {
               System.Diagnostics.Debug.WriteLine($"n+m={n+m}");
           }
       }
   }
}

运行结果

n+m=63
n+m=63

三、使用图形观察

圆与第一象限中整数相交的点为答案,将点的 x x x y y y进行相加得到计算结果

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Subject3LightSimulation
{
    public partial class Form3 : Form
    {
        float radius = 0;
        public Form3()
        {
            InitializeComponent();
            radius =(float) Math.Sqrt(2009);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            using (Brush b = new SolidBrush(Color.FromArgb(192,192,192,192)))
            {
                using (Pen p = new Pen(b))
                {
                    p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                    for (int i = 0; i < 100; i++)
                    {
                        e.Graphics.DrawLine(p, new Point(0, i * 10), new Point(1000, i * 10));
                    }

                    for (int i = 0; i < 100; i++)
                    {
                        e.Graphics.DrawLine(p, new Point(i * 10, 0), new Point(i * 10, 1000));
                    }
                }
            }
            using (Brush b = new SolidBrush(Color.Blue))
            {
                using (Pen p = new Pen(b))
                {
                        e.Graphics.DrawLine(p, new Point(0, 500), new Point(1000,500));
                        e.Graphics.DrawLine(p, new Point(500, 0), new Point(500, 1000));
                }
            }

            using (Brush b2 = new SolidBrush(Color.Red))
            {
                using (Pen p2 = new Pen(b2))
                {
                    float x = 500 - radius*10;
                    float y = 500 - radius * 10;
                    float w = 2 * radius * 10;
                    float h = 2 * radius * 10;
                    float s = 0.0f;
                    float e2 = 360;
                    e.Graphics.DrawArc(p2, x,y,w,h,s,e2);
                }
            }

            using (Brush b2 = new SolidBrush(Color.Red))
            {
                using (Pen p2 = new Pen(b2))
                {
                    float x = 500 - 1 * 10;
                    float y = 500 - 1 * 10;
                    float w = 2 * 1 * 10;
                    float h = 2 * 1 * 10;
                    float s = 0.0f;
                    float e2 = 360;
                    e.Graphics.DrawArc(p2, x, y, w, h, s, e2);
                }
            }

            using (Brush b2 = new SolidBrush(Color.Green))
            {
                using (Pen p2 = new Pen(b2))
                {
                    int x = 500 + 28 * 10;
                    int y = 500 - 35 * 10;
                    e.Graphics.DrawLine(p2, new Point(500, 500), new Point(x, y));


                    int x2 = 500 + 35 * 10;
                    int y2 = 500 - 28 * 10;
                    e.Graphics.DrawLine(p2, new Point(500, 500), new Point(x2, y2));
                }

                using (Pen p3 = new Pen(b2))
                {
                    p3.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                    int x = 500 + 28 * 10;
                    int y = 500 - 35 * 10;
                    e.Graphics.DrawLine(p3, new Point(x, 500), new Point(x, y));
                    e.Graphics.DrawLine(p3, new Point(x, y), new Point(500, y));


                    int x2 = 500 + 35 * 10;
                    int y2 = 500 - 28 * 10;
                    e.Graphics.DrawLine(p3, new Point(x2, 500), new Point(x2, y2));
                    e.Graphics.DrawLine(p3, new Point(x2, y2), new Point(500, y2));
                }
            }


            using (Brush b2 = new SolidBrush(Color.Green))
            {
                using (Pen p2 = new Pen(b2))
                {
                    int x = 500 + 28 * 10;
                    int y = 500 - 35 * 10;
                    e.Graphics.DrawString("28",Font, b2, new Point(x, 500));
                    e.Graphics.DrawString("35", Font, b2, new Point(500, y));
                    e.Graphics.DrawString("_____", Font, b2, new Point(x/2 + 250+ (int)Font.Size + 1, y/2 + 250-Font.Height+3));
                    e.Graphics.DrawString("√2009", Font, b2, new Point(x/2 + 250, y/2 + 250));


                    int x2 = 500 + 35 * 10;
                    int y2 = 500 - 28 * 10;
                    e.Graphics.DrawString("35", Font, b2, new Point(x2, 500));
                    e.Graphics.DrawString("28", Font, b2, new Point(500, y2));
                    e.Graphics.DrawString("_____", Font, b2, new Point(x2/2 + 250 + (int)Font.Size+1, y2/2 + 250 - Font.Height + 3));
                    e.Graphics.DrawString("√2009", Font, b2, new Point(x2/2+250, y2/2 + 250));
                }
            }
        }
    }
}

运行结果在这里插入图片描述

扩展

html中使用table元素表示短除

<html>
<body>
<table>
  <tr>
  	<td width="40px"></td>
    <td width="20px"></td>
    <td width="40px"></td>
  </tr>
  <tr>
  	<td style="text-align:right">7</td>
    <td style="text-algin:center;border-left:2px solid #000;border-bottom:2px solid #000;" align="center" colspan="3">2009</td>
  </tr>
  <tr>
  	<td></td>
    <td style="text-align:right">7</td>
    <td style="text-algin:center;border-left:2px solid #000;border-bottom:2px solid #000;"  align="center" colspan="2">287</td>
  </tr>
  <tr>
  	<td ></td>
    <td ></td>
    <td style="text-align:center">41</td>
  </tr>
</table>
</body>
</html>

使用上述代码亲自试一试

显示效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值