結果

問題 No.2349 Power!! (Hard)
ユーザー maksimmaksim
提出日時 2023-06-09 22:33:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 776 bytes
コンパイル時間 5,344 ms
コンパイル使用メモリ 165,008 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2023-08-30 13:41:29
合計ジャッジ時間 13,114 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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