AT_fps_24_b 整数の組

生成函数是简单的,列出生成函数 然后对后两个的分母因式分解发现能和前两项消掉,最后是 \([x^n]\frac{1}{(x-1)^2}\)

还有一种是枚举前两种,然后 \(d\)\(t=n-a-b\) 模 2 同余,且满足 \(3d\le t\) 所以看 \(\lfloor\frac{t}{3}\rfloor\) 中有多少个数与 \(t\) 同余。

还有一种比较高妙是 \(a,c\) 配对 \(b,d\) 配对,当 \(a+c\) 取得某值时 \(a,c\) 对应的方案唯一,\(b,d\) 同理。而 \(a+b+c+d=n\) 所以确定了 \(a+c\) 就相当于确定了 \(a,b,c,d\),而 \(a+c\in[0,n]\),所以一共有 \(n+1\) 种。

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define fr(x) fin(x),fout(x);
#define Fr(x,y) fin(x),fout(y)
#define INPUT(_1,_2,FILE,...) FILE
#define IO(...) INPUT(__VA_ARGS__,Fr,fr)(__VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
#define mp make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define cfast ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
#define ll long long
#define ull unsigned long long
#define intz(x,y) memset((x),(y),sizeof((x)))
char *p1,*p2,buf[100000];
#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++)
#define tup(x) array<int,(x)>
inline ll read(){
    ll x=0,f=1;char ch=nc();
    while(ch<48||ch>57){if(ch=='-')f=-1;ch=nc();}
    while(ch>=48&&ch<=57)x=x*10+ch-48,ch=nc();
   	return x*f;
}
//void write(int x){cout<<x<<' ';}
//void write(pii x){cout<<"P("<<x.fi<<','<<x.se<<")\n";}
//void write(vector<auto>x){for(auto i:x)write(i);cout<<'\n';}
//void write(auto *a,int l,int r){for(int i=l;i<=r;i++)write(a[i]);cout<<'\n';}
inline ll lowbit(ll x){return x&-x;}
inline int pcount(ll x){
	for(int i=0,res=0;;res+=(x>>i)&1,i++)
		if(i>60)return res;
}

//struct mt{
//	ll v;
//	mt(){v=0;}
//	mt(int x){this->v=x;}
//	inline mt operator+(mt x){return {(v+x.v)%mod};}
//	inline mt operator-(mt x){return {(v+mod-x.v)%mod};}
//	inline mt operator*(mt x){return {1ll*v*x.v%mod};}
//};
//inline void add(mt &x,mt y){x=x+y;}
//mt qp(mt x,int y){mt res(1);for(;y;x=x*x,y>>=1)if(y&1)res=res*x;return res;}
const int mod=998244353;
inline void UesugiErii(){
	int n;ll ans=0;cin>>n;
	for(int a:{0,1})
		for(int b:{0,1,2}){
			int tmp=n-a-b;
			if(tmp<0)break;
			if(tmp&1)
				(ans+=((tmp/3)&1?(tmp/3+2)/2:(tmp/3+1)/2)%mod)%=mod;
			else (ans+=((tmp/3)&1?(tmp/3+1)/2:(tmp/3+2)/2)%mod)%=mod;
		}
	cout<<ans;
}
signed main(){
	//IO();//cfast;
	int _=1;//cin>>_;
	for(;_;_--)UesugiErii();
	return 0;
}
posted @ 2025-11-27 20:37  Uesugi1  阅读(0)  评论(0)    收藏  举报