#include<iostream>
#include<string>
using namespace std;
int M, N;
string first = "0", second = "1", third = "";
void factorial()
{
int temp;
for (int i = 0; i < N; i++)
{
temp = 0;
third.clear();
for (int j = 0; j < first.length(); j++)
{
third += char((temp + first[j] - '0' + second[j] - '0') % 10 + '0');
temp = (temp + first[j] - '0' + second[j] - '0') / 10;
}
if (temp > 0 || second.length() > first.length())
{
if (second.length() > first.length())
temp += second[first.length()] - '0';
third += char(temp + '0');
}
first = second;
second = third;
}
}
int main()
{
cin >> M >> N;
N = N - M;
factorial();
for (int i = third.length() - 1; i >= 0; i--)
cout << third[i];
return 0;
}
洛谷P2437 蜜蜂路线进阶解法
最新推荐文章于 2025-08-29 11:21:35 发布
这是一个用C++编写的程序,它计算并输出从M到M+N的阶乘序列。程序首先读取M和N的值,然后通过迭代计算阶乘,将结果存储在字符串third中,并最终逆序输出。
902

被折叠的 条评论
为什么被折叠?



