結果

問題 No.2349 Power!! (Hard)
ユーザー maksim
提出日時 2023-06-09 22:33:28
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 776 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 162,300 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2025-01-02 03:54:44
合計ジャッジ時間 92,305 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}
int inv(int x) {return po(x,p-2);}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int h=(1<<12)*7*17;
    int t;cin>>t;while(t--)
    {
    int a,n;cin>>a>>n;
    int res=0;
    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;int u=po(a,step);
        if(u!=1) {int inva=inv(u-1);res+=(po(a,r)-po(a,l))*inva;res%=p;}
        else {res+=po(a,l)*o;res%=p;}
    }
    cout<<(res%p+p)%p<<'\n';
    }
    return 0;
}
0