結果
| 問題 |
No.2348 Power!! (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-09 22:52:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,325 bytes |
| コンパイル時間 | 1,531 ms |
| コンパイル使用メモリ | 162,960 KB |
| 実行使用メモリ | 13,636 KB |
| 最終ジャッジ日時 | 2025-01-02 04:36:11 |
| 合計ジャッジ時間 | 58,074 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
}
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;}
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=inverse(u-1,p);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;
}