华为OD机试真题 - 用连续自然数之和来

列方程 double L= (num * 2 + i - i * i) / 4.0;
如果 L 是整数就存在

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        System.out.println(getReslut(num));
    }

    public static int getReslut(int num) {
        int count = 1;
        for (int i = 1; i <= num / i; i++) {
            double temp = (num * 2 + i - i * i) / 4.0;
            if (temp == (int)temp)
                count++;
        }
        return count;
    }
全部评论

相关推荐

完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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