猛锌求diao
查看原帖
猛锌求diao
590600
Kreado楼主2023/6/2 21:10
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll Mod=998244353,inv2=499122177,inv6=166374059;
struct node{
    ll f,g,h;
    node(){
        f=g=h=0;
    }
};
inline ll up(ll x){
    return (x%Mod+Mod)%Mod;
}
inline node Get1(ll n,ll a,ll b,ll c){
    ll ac=a/c,bc=b/c,L=(a*n+b)/c;
    node ans;   
    if(a>=c||b>=c){
        node x=Get1(n,a%c,b%c,c);
        ans.f=up(up(ac*n%Mod*(n+1)%Mod*inv2%Mod)+up(bc*(n+1))%Mod+x.f);
        ans.g=up(up(n*(n+1)%Mod*(2*n+1)%Mod*inv6%Mod*ac%Mod)+up(n*(n+1)*inv2%Mod*bc%Mod)+x.g);
        ans.h=up(up(x.h+2*bc%Mod*x.f%Mod)+up(2*ac%Mod*x.g%Mod)+
        up(n*(n+1)%Mod*(2*n+1)%Mod*inv6)%Mod*ac%Mod*ac%Mod+
        up((n+1)*bc%Mod*bc%Mod)+up(n*(n+1)%Mod*ac%Mod*bc%Mod));
        return ans;
    }
    if(!a){
        ans.f=(n+1)*bc%Mod;
        ans.g=(n+1)*n%Mod*inv2%Mod*bc%Mod;
        ans.h=(n+1)*bc%Mod*bc%Mod;
        return ans;
    }
    node x=Get1(L-1,c,c-b-1,a);
    ans.f=up(n*L-x.f);
    ans.g=up(n*(n+1)%Mod*L%Mod-x.f-x.h)*inv2%Mod;ans.g=up(ans.g);
    ans.h=up(n*(L+1)%Mod*L%Mod-2*x.f-2*x.g)-ans.f;ans.h=up(ans.h);
    return ans;
}
ll T,n,a,b,c;
int main(){
    scanf("%lld",&T);
    while(T--){
        scanf("%lld%lld%lld%lld",&n,&a,&b,&c);
        node s=Get1(n,a,b,c);
        printf("%lld %lld %lld\n",s.f,s.h,s.g);
    }
    return 0;
}

估计是驱魔错了,各位魔导师帮帮我那个步骤错了

虱子检查了,应该没有错,就是驱魔问题吧

2023/6/2 21:10
加载中...