HDOJ:阶乘取余

一道关于递推的题目,题目链接在这里

Problem Description
来个阶乘的题,给一个不超过100000的整数N,请求出Sum=1!+2!+3!+…….+N!。如果N很大,那结果的位数会不会太多?那好,如果Sum超过6位数,只要求最后6位数,这样简单了吧
Input
每组数据包含一个整数N(1取余的时候注意前面加括号,多么痛的领悟……
代码:

#include
#include
using namespace std;
__int64 sum[100000] = { 1, 1 };
int math(int a)
{
	int j;
	__int64 cache = 1;
	for (j = 2; j 

精简代码By郭晓磊:

#include
int main()
{
    int n,i;
    __int64 x[100005],temp;
    x[1]=temp=1;
    for(i=2;i
	

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注