五边形型数

1:一个讲解的很详细的五边型数的博客http://blog.csdn.net/zhoufenqin/article/details/9821617;

2:题目;hdu4651,最简单的五边形数,母函数应该也可以做(N^3),,五边形数是(N^1.5);

   HDU4658,5230;变形版;

HDU5230的代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

typedef __int64 LL;
const int Maxn=100010;
const LL MOD=998244353;
LL Q[Maxn],P[Maxn];
LL GetQ(LL x)
{
    LL ans=(LL)x*x*3-x;
    return (ans/2)%MOD;
}
void _init()
{
    Q[0]=0;
    for(int i=1;i<Maxn;i++)
    {
        if(i&1) Q[i]=GetQ(i/2+1);
        else Q[i]=GetQ(i/2*(-1));
    }
    P[0]=P[1]=1;
    for(int i=2;i<Maxn;i++)
    {
        for(int j=1;;j++)
        {
            if(Q[j]>i) break;
            int t=j;
            if(t&1) t=t/2+1;
            else t=t/2;
            if(t&1)
                P[i]=(P[i]+P[i-Q[j]]);
            else
                P[i]=(P[i]-P[i-Q[j]]);
            if(P[i]>=MOD) P[i]%=MOD;
            if(P[i]<0) P[i]+=MOD;
        }
    }
}
LL solved(LL n)
{
    LL ans=0;
    for(int i=0;;i++)
    {
        if(Q[i]*2>n) break;
        //cout<<i<<" "<<Q[i]<<endl;
        int t=i;
        if(t&1) t=t/2+1;
        else t=t/2;
        if(t&1) ans=(ans-P[n-Q[i]*2]);
        else ans=(ans+P[n-Q[i]*2]);
        if(ans>=MOD) ans%=MOD;
        if(ans<0) ans+=MOD;
        //cout<<ans<<endl;
    }
    //printf("%I64d\n",ans);
    return ans;
}
int main()
{
    _init();
    int T;
    scanf("%d",&T);
    while(T--)
    {
        LL C,L,D,n;
        scanf("%I64d%I64d%I64d%I64d",&n,&C,&L,&D);
        int i;
        LL ans=0;
        for(i=L-C;i<=D-C;i++)
        {
            ans+=solved(i);
            ans=(ans+MOD)%MOD;
            //cout<<ans<<endl;
        }
       printf("%I64d\n",ans);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值