题解 | #尼科彻斯定理#

尼科彻斯定理

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

找规律:
(1)n前数字个数为:startCount = n*(n+1)/2-n;
(2)n第一个数字为:startNum = 2 * startCount +1;
using System;

namespace HJ76{
    class Solution{
        public static void Main(){
            var input = Convert.ToInt32(Console.ReadLine());
            int startCount = input *(input+1)/2 - input;
            int startNum = 2 * startCount + 1;
            for(int i = 0; i < input; i++){
                if(i < input-1 ){
                    Console.Write(startNum+2*i + "+");
                }else{
                    Console.Write(startNum+2*i);
                }
            }
        }
    }  
}


全部评论

相关推荐

09-01 09:00
已编辑
四川旅游学院 运营
牛客55195891...:主要是专业不好,别的没毛病
牛客解忧铺
点赞 评论 收藏
分享
叁六玖:你看,最后不是让你加油,就是鼓励你,还祝福你求职顺利。
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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