結果
| 問題 |
No.2349 Power!! (Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-09 23:21:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,774 bytes |
| コンパイル時間 | 1,845 ms |
| コンパイル使用メモリ | 162,224 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-01-02 05:31:45 |
| 合計ジャッジ時間 | 78,883 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 TLE * 8 |
ソースコード
#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;
}