51nod 1138 连续整数的和
2017-07-24 15:17
211 查看
等差数列前n项和公式:S = na1+n(n-1)/2,a1 = (S-n(n-1)/2)/n,可以求出n的范围大概就是[2,sqrt(2*S)],枚举序列长度n,然后求解a1。
using System; using System.IO; using System.Numerics; namespace timeless { class Program { static void Main(string[] args) { StreamReader sr = new StreamReader(Console.OpenStandardInput()); StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); int n = Convert.ToInt32(sr.ReadLine()); int len = (int)Math.Sqrt(n*2); bool flag = false; for (int i = len; i >= 2; --i) { if ((n - (i * (i - 1)) / 2) % i == 0) { flag = true; sw.WriteLine((n - (i * (i - 1)) / 2)/ i); } } if (!flag) sw.WriteLine("No Solution"); sw.Flush(); sw.Close(); sr.Close(); } } }
相关文章推荐
- 【51nod】--1138 连续整数的和 (思维)
- 51nod 1138 连续整数的和
- 51nod 1138 连续整数的和 (规律)
- 51NOD 1138 连续整数的和
- 51Nod-1138-连续整数的和
- 51nod--1138 . 连续整数的和
- 51nod 1138 连续整数的和(牛逼)
- 51Nod 1138 连续整数的和
- 51nod 1138 连续整数的和(数学)
- 51Nod 1138 连续整数的和
- 51nod 1138 连续整数的和
- 51nod 1138 连续整数的和 【栈操作】
- 51nod 1138 连续整数的和
- 51nod 1138 连续整数的和 (数学公式_转换思想,好题吧)
- 51Nod 1138 连续整数的和(数学、规律)
- 51nod 1138 连续整数的和
- 51nod 1138 连续整数的和(数学)
- 【51Nod】1138 连续整数的和
- 51Nod 1138 连续整数的和
- 51nod--1138 . 连续整数的和