题解 | #尼科彻斯定理#
尼科彻斯定理
https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85
// HJ76 尼科彻斯定理.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int three_sqrt = n * n * n;
int sum = 0;
for (int i = 1; i < three_sqrt; i += 2)
{
sum = n * (i + n - 1);//使用等差数列求和公式判断Sn=a1n+n(n-1)d/2;Sn=(a1+an)n/2
if (sum == three_sqrt)
{
for (int j = i; j < i+2*(n-1); j+=2)
{
cout << j << '+';//输出
}
cout << i + 2 * (n - 1) << endl;
return 0;//结束循环
}
}
}
return 0;
}

查看17道真题和解析