static void Main(string[] args)
{
string tj = "";
int num = 0;
Console.Write("请输入1个整数!\r\n");
tj = Console.ReadLine().Trim();
if (Int32.TryParse(tj, out num))
{
num = Convert.ToInt32(tj);
}
else
Console.Write("请输入正确的整数!");
string text = "";
for (int i = 1; i < num; i++)
{
for (int j = num - 1; j >= 1&&j>i; j--)
{
if ((i + j) * 0.5 * Math.Abs(j - i+1) == num && i != j)
{
if (text != "")
{
text += "\r\n";
}
for (int k = i; k <= j; k++)
{
text += k.ToString() + " ";
}
text = text.Substring(0, text.Length - 1);
}
}
}
if (text == "")
{
Console.Write("不存在满足条件的序列!");
}
else
Console.Write(text);
Console.ReadLine();
}
温馨提示:答案为网友推荐,仅供参考