結果
| 問題 | No.3572 Number of special equations |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-16 23:49:09 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,393 bytes |
| 記録 | |
| コンパイル時間 | 2,176 ms |
| コンパイル使用メモリ | 331,712 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-06-19 20:51:01 |
| 合計ジャッジ時間 | 5,233 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=998244353;
const long long FACSIZE=1048576;
long long power(long long a,long long b){
long long x=1,y=a;
while(b>0){
if(b&1ll){
x=(x*y)%mod;
}
y=(y*y)%mod;
b>>=1;
}
return x%mod;
}
long long modular_inverse(long long n){
return power(n,mod-2);
}
long long factorial[FACSIZE];
long long invfact[FACSIZE];
void cfact(){
long long i;
factorial[0]=1;
factorial[1]=1;
for(i=2;i<FACSIZE;i++){
factorial[i]=factorial[i-1]*i;
factorial[i]%=mod;
}
invfact[FACSIZE-1]=modular_inverse(factorial[FACSIZE-1]);
for(i=FACSIZE-2;i>=0;i--){
invfact[i]=invfact[i+1]*(i+1);
invfact[i]%=mod;
}
}
long long calcnCr(long long n,long long k){
if(k<0 || n<k){return 0;}
return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}
// int main(){
// cfact();
// for(ll N=1;N<=40;N++){
// ll res=1;
// for(ll n=1;n<=N;n++){
// if(n%2==1){
// ll pn=(n/2);
// for(ll a=0;a<=N;a++){
// for(ll b=1;a+b<=N;b++){
// ll rem=N-a-b;
// if(pn==0){
// if(rem==0){res++;}
// continue;
// }
// if(rem>=pn*2 && rem%2==0){
// rem/=2; rem-=pn;
// res+=calcnCr(rem+pn-1,pn-1); res%=mod;
// }
// }
// }
// }
// else{
// ll pn=(n/2)-1;
// for(ll a=0;a<=N;a++){
// for(ll b=1;a+b<=N;b++){
// for(ll c=1;a+b+c<=N;c++){
// ll rem=N-a-b-c;
// if(pn==0){
// if(rem==0){res++;}
// continue;
// }
// if(rem>=pn*2 && rem%2==0){
// rem/=2; rem-=pn;
// res+=calcnCr(rem+pn-1,pn-1); res%=mod;
// }
// }
// }
// }
// }
// }
// cout << N << " " << res%mod << "\n";
// }
// return 0;
// }
ll A131064(ll n){
ll a=(5ll*power(2,n))%mod;
ll b=(4*(n+1))%mod;
return (mod+a-b)%mod;
}
ll A027383(ll n){
if(n%2==0){
n/=2;
return (mod+3ll*power(2,n)-2)%mod;
}
else{
n/=2;
return (mod+power(2,n+2)-2)%mod;
}
}
int main(){
ll N;
cin >> N;
if(N%2==1){
cout << A131064((N+1)/2) << "\n";
}
else{
cout << (A131064(N/2)+A027383(N-1))%mod << "\n";
}
}