結果
問題 | No.2060 AND Sequence |
ユーザー |
👑 |
提出日時 | 2022-08-27 13:18:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,681 bytes |
コンパイル時間 | 1,829 ms |
コンパイル使用メモリ | 193,240 KB |
最終ジャッジ日時 | 2025-01-31 06:24:25 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include<bits/stdc++.h>using namespace std;using uint = unsigned int;using ll = long long;#define CIN( LL , A ) LL A; cin >> A#define GETLINE( A ) string A; getline( cin , A )#define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR )#define FOR_LL( VAR , INITIAL , FINAL_PLUS_ONE ) for( ll VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )#define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ )#define REPEAT( HOW_MANY_TIMES ) FOR_LL( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES )#define RETURN( ANSWER ) cout << ( ANSWER ) << endl; return 0#define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( ANSWER ) << endl; return 0#define MIN( A , B ) A < B ? A : B;#define MAX( A , B ) A < B ? B : A;template <typename T> inline T Distance( const T& a , const T& b ){ return a < b ? b - a : a - b; }constexpr const ll D = 30;constexpr const ll P = 998244353;int main(){CIN( ll , N );CIN( ll , M );bool b[D] = {};ll M_copy = M;FOR_LL( d , 0 , D ){if( M_copy % 2 == 1 ){b[d] = true;}M_copy /= 2;}ll N_plus = N + 1;ll power_N_plus = 1;ll add[D] = {};FOR_LL( d , 0 , D ){if( b[d] ){add[d] = power_N_plus;}power_N_plus = ( power_N_plus * N_plus ) % P;}ll power_N = 1;FOR_LL( d , 0 , D ){ll d_neg = D - 1 - d;if( b[d_neg] ){add[d_neg] *= power_N;power_N = ( power_N * N ) % P;}}ll answer = 0;FOR_LL( d , 0 , 30 ){if( b[d] ){answer = ( answer + add[d] ) % P;}}answer = ( answer + power_N ) % P;RETURN( answer );}