結果

問題 No.2348 Power!! (Easy)
ユーザー maksimmaksim
提出日時 2023-06-09 22:49:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,351 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 165,040 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-30 13:59:58
合計ジャッジ時間 36,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h=(1<<12)*7*17;int sz=((p-1)/h+1);
    int t;cin>>t;while(t--)
    {
    int a,n;cin>>a>>n;
    int invs[sz];for(int i=0;i<sz;++i) invs[i]=inverse(po(a,i*h)-1,p);
    int res=0;
    int cur1=1;int cur2=1;int t=1;int u1=1;int u2=po(a,2*h);int u=1;
    for(int i=0;i<h;++i)
    {
        if(i>=n) continue;
        int o=(n-1-i)/h+1;
        int l=i*i;int r=i*i+o*i*2*h;
        int step=2*i*h;if(i) {u*=u2;u%=p;}
        u1=po(a,o*2*h);
        if(i==0 || (n-i-1)/h!=(n-i)/h)
        {
            t=po(a,o*i*2*h);u1=po(a,o*2*h);
        }
        else
        {
            t*=u1;t%=p;
        }
        if(u!=1) {int inva=invs[((2*i)%sz)];int v=(cur1*t)%p;res+=(v-cur1)*inva;res%=p;}
        else {res+=cur1*o;res%=p;}
        cur1*=cur2;cur1%=p;cur1*=cur2;cur1%=p;cur1*=a;cur1%=p;cur2*=a;cur2%=p;
    }
    cout<<(res%p+p)%p<<'\n';
    }
    return 0;
}
0