結果
| 問題 |
No.2060 AND Sequence
|
| コンテスト | |
| ユーザー |
蜜蜂
|
| 提出日時 | 2022-08-26 22:30:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,980 bytes |
| コンパイル時間 | 3,647 ms |
| コンパイル使用メモリ | 229,040 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-13 23:09:17 |
| 合計ジャッジ時間 | 5,174 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
コンパイルメッセージ
main.cpp: In function 'vll popcount(int)':
main.cpp:86:1: warning: control reaches end of non-void function [-Wreturn-type]
86 | }
| ^
ソースコード
//https://judge.yosupo.jp/submission/33179
//g++ 1.cpp -std=c++17 -O2 -I .
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())
constexpr ll mod = 998244353;
const int MAX=100;
const long long MOD=998244353;
long long fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for(int i=2;i<MAX;i++){
fac[i]=fac[i-1]*i%MOD;
inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
finv[i]=finv[i-1]*inv[i]%MOD;
}
}
long long COM(int n,int k){
if(n<k) return 0;
if(n<0||k<0) return 0;
return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
vll popcount(int m){
vll res(35,0);
if(m==0){
res[0]=1;
return res;
}
if(m==1){
res[0]=1;
res[1]=1;
return res;
}
if(m==2){
res[0]=1;
res[1]=2;
return res;
}
rep(i,1,40){
ll pw=(1LL<<i);
if(pw<=m&&m<2*pw){
vll sub=popcount(m-pw);
rep(j,0,i+1){
res[j]=COM(i,j);
}
rep(j,0,34){
res[j+1]+=sub[j];
}
return res;
}
}
}
/*
A_N = x := N^popcount(x)
N=3 M=3
0 1
1 3
2 3
3 9
*/
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
COMinit();
int n,m;
cin>>n>>m;
vll p=popcount(m);
ll ans=0;
rep(i,0,35){
ans+=p[i]*pow_mod(n,i,mod);
ans%=mod;
}
cout<<ans<<endl;
}
蜜蜂