一只羊的四个月可以生一只小羊,小羊四个月后又可以生一只小羊 问50个月后有多少只羊(羊不会死)
/// <summary> /// 获得羊 /// </summary> /// <param name="day">月数</param> /// <param name="initialSheepNum">初始有多少只羊</param> /// <returns></returns> public ulong Sheep(int day, ulong initialSheepNum = 1) { ulong all = initialSheepNum; ulong a = 0; ulong b = 0; ulong c = 0; for (int i = 0; i < day; i++) { // Console.WriteLine(all); all += c; c = b; b = a; a = all; } return all; }