题解 | #尼科彻斯定理#

尼科彻斯定理

https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85

using System;
using System.Text;

namespace HJ76
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int m = int.Parse(Console.ReadLine());

            if (m == 1)
            {
                Console.WriteLine(1);
                return;
            }

            StringBuilder sb = new StringBuilder();

            //m*m*m=m*(m*m)=2*m*m*m/2=((m*m-m+1)+(m*m+m-1))/2*m
            //初始项目为m*m-m+1,公差为2的递增数列
            for (int i = 0; i < m; i++)
            {
                int num = m * m - m + 1 + 2 * i;
                sb.Append(num);
                if (i < m - 1)
                {
                    sb.Append('+');
                }
            }

            Console.WriteLine(sb.ToString());

        }
    }
}

全部评论

相关推荐

只因飞飞:今日首绷
点赞 评论 收藏
分享
10-20 11:11
辽宁大学 营销
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务