結果

問題 No.2349 Power!! (Hard)
ユーザー maksimmaksim
提出日時 2023-06-09 23:21:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,774 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 166,320 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 14:35:18
合計ジャッジ時間 75,548 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 KB
testcase_01 AC 4,157 ms
4,380 KB
testcase_02 AC 4,328 ms
4,376 KB
testcase_03 AC 4,231 ms
4,380 KB
testcase_04 AC 951 ms
4,376 KB
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b){
  int x = a, res = 1;
  int h = b;
  while (h > 0) {
    if (h & 1) {res *= x;res%=p;}
    x *= x;x%=p;
    h >>= 1;
  }
  return res;
}
int inverse(int a,int m) {
  int u = 0, v = 1;
  while (a != 0) {
    int t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  return u;
}
const int h=(1<<12)*7*17;
const int sz=((p-1)/h);
int g[1024][2];
int sum[1024][2];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;cin>>t;while(t--)
    {
    int a,n;cin>>a>>n;int u2=po(a,h);int cur=1;
    int pos[sz];for(int i=0;i<sz;++i) {pos[i]=cur;cur*=u2;cur%=p;}
    int invs[sz];for(int i=0;i<sz;++i) invs[i]=inverse(pos[i]-1,p);
    for(int i=0;i<1024;++i)
    {
        for(int j=0;j<2;++j)
        {
            sum[i][j]=0;
            int o=(j==0 ? (n-1)/h : (n-h)/h);++o;
            int u=pos[(2*i)%sz];
            int t=po(a,o*i*2*h);
            if(u!=1) {int inva=invs[(2*i)%sz];int res=(t-1)*inva;res%=p;g[i][j]=res;}
            else {g[i][j]=o;}
        }
    }
    int cur1=1;int cur2=a;int t=1;int u1=1;int u=1;int a2=(a*a)%p;
    for(int i=0;i<h;++i)
    {
        if(i>=n) continue;
        int o=(n-1-i)/h+1;
        if(o==(n-1)/h+1)
        {
            sum[i%1024][0]+=cur1;if(sum[i%1024][0]>=p) sum[i%1024][0]-=p;
        }
        else
        {
            sum[i%1024][1]+=cur1;if(sum[i%1024][1]>=p) sum[i%1024][1]-=p;
        }
        cur1*=cur2;cur1%=p;cur2*=a2;cur2%=p;
    }
    int res=0;
    for(int i=0;i<1024;++i)
    {
        for(int j=0;j<2;++j)
        {
            res+=g[i][j]*sum[i][j];
            res%=p;
        }
    }
    cout<<(res%p+p)%p<<'\n';
    }
    return 0;
}
0