QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#119690 | #6179. 最大平方问题 | serene_analysis | 0 | 33ms | 9276kb | C++17 | 3.2kb | 2023-07-05 14:53:23 | 2023-07-05 14:53:26 |
Judging History
answer
#include<algorithm>
#include<chrono>
#include<cstdio>
#include<random>
#include<vector>
#include<cmath>
#include<ctime>
#include<map>
std::mt19937_64 tian(std::chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
const int maxn=4e5+5;
const int amod=998244353;
int pri[maxn],pcnt;
bool isnt[maxn];
void sift(int lim){
for(int i=2;i<=lim;i++){
if(!isnt[i])pri[++pcnt]=i;
for(int j=1;j<=pcnt&&1ll*i*pri[j]<=lim;j++){
isnt[i*pri[j]]=true;
if(i%pri[j]==0)break;
}
}
return;
}
ll mul(ll now,ll oth,ll mod){return (__int128)(now)*oth%mod;}
ll qpow(ll a,ll b,ll mod){
ll ans=1;
while(b){
if(b&1)ans=mul(ans,a,mod);
a=mul(a,a,mod);
b>>=1;
}
return ans;
}
namespace cipolla{
struct cpx{ll rea,ima;};
cpx cmul(cpx now,cpx oth,ll mod){
return (cpx){(mul(now.rea,oth.rea,mod)+mod-mul(now.ima,oth.ima,mod))%mod,
(mul(now.rea,oth.ima,mod)+mul(now.ima,oth.rea,mod))%mod};}
ll leg(ll x,ll mod){return qpow(x,(mod-1)/2,mod);}
void sqrest(ll x,ll mod,ll &fi,ll &se){
if(leg(x,mod)==mod-1){
fi=-1,se=-1;
return;
}
while(true){
ll gue=tian()%mod,now=(mul(gue,gue,mod)-x+mod)%mod;
// printf("mod=%lld,gue=%lld,now=%lld,leg=%lld\n",mod,gue,now,leg(now,mod));
if(leg(now,mod)==mod-1){
cpx ret=(cpx){1,0},step=(cpx){gue,1};
ll up=(mod+1)/2;
while(up){
if(up&1)ret=cmul(ret,step,mod);
step=cmul(step,step,mod);
up>>=1;
}
fi=ret.rea,se=mod-ret.rea;
return;
}
}
return;
}
};
std::map<ll,int>apr;
std::map<ll,bool>vis;
void divide(ll &x,ll p,int coe){
// printf("divide:%lld,%lld,%d\n",x,p,coe);
while(x%p==0)x/=p,apr[p]+=coe;
return;
}
int a,b,c,n;
ll f[maxn],g[maxn];
void go(ll p){
if(p==2||a%p==0)for(int i=1;i<=n;i++)/*printf("i=%d\n",i),*/divide(f[i],p,1);
else{
ll fi=-1,se=-1,rv=mul((mul(b,b,p)-mul(4*a,c,p)+p)%p,qpow(mul(4*a,a,p),p-2,p),p);
// printf("rv=%lld\n",rv);
cipolla::sqrest(rv,p,fi,se);
// printf("fi=%lld,se=%lld\n",fi,se);
if(fi!=-1){
ll dec=mul(b,qpow(2*a,p-2,p),p);
fi=(fi-dec+p)%p,se=(se-dec+p)%p;
if(fi==0)fi=p;
if(se==0)se=p;
for(ll i=fi;i<=n;i+=p)/*printf("i=%lld\n",i),*/divide(f[i],p,1);
for(ll i=se;i<=n;i+=p)/*printf("i=%lld\n",i),*/divide(f[i],p,1);
}
}
return;
}
signed main(){
scanf("%d%d%d%d",&a,&b,&c,&n);
for(int i=1;i<=n;i++)f[i]=1ll*a*i*i+1ll*b*i+c;
for(int i=1;i<=2*n;i++)g[i]=1ll*a*i+b;
int lim=std::max({n,(int)(std::pow(f[n],1.0/3)),(int)(std::sqrt(g[2*n]))});
// printf("lim=%d\n",lim);
sift(lim);
for(int i=1;i<=pcnt;i++){
int p=pri[i];
// printf("i=%d,p=%d\n",i,p);
go(p);
if(a%p==0||b%p==0){
// printf("a,b mod p=0\n");
for(int j=1;j<=2*n;j++)divide(g[j],p,0);
}
else{
// printf("a=%d,b=%d,p=%d\n",a,b,p);
int st=1ll*(p-b%p)*qpow(a,p-2,p)%p;
// printf("st=%d\n",st);
for(int j=st;j<=2*n;j+=p)divide(g[j],p,0);
}
}
vis[1]=true;
for(int i=1;i<=2*n;i++)if(!vis[g[i]])vis[g[i]]=true,go(g[i]);
for(int i=1;i<=n;i++)if(f[i]!=1){
int sq=std::sqrt(f[i])+0.1;
if(1ll*sq*sq==f[i])apr[sq]+=2;
}
int ans=1;
for(auto now:apr)ans=1ll*ans*qpow(now.first,(now.second/2)*2,amod)%amod;
printf("%d",ans);
return 0;
}
//namespace burningContract
详细
Test #1:
score: 0
Time Limit Exceeded
input:
17 3 17 14
output:
result:
Test #2:
score: 0
Time Limit Exceeded
input:
1 18 0 6
output:
result:
Test #3:
score: 0
Time Limit Exceeded
input:
20 6 20 14
output:
result:
Test #4:
score: 0
Time Limit Exceeded
input:
81 190 40 125
output:
result:
Test #5:
score: 0
Wrong Answer
time: 2ms
memory: 7348kb
input:
108 31 110 122
output:
240048225
result:
wrong answer 1st numbers differ - expected: '319532761', found: '240048225'
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 7492kb
input:
988 194 1412 934
output:
78660307
result:
wrong answer 1st numbers differ - expected: '871618879', found: '78660307'
Test #7:
score: 0
Time Limit Exceeded
input:
1956 1305 92 1061
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
75955 165029 149078 5607
output:
result:
Test #9:
score: 0
Wrong Answer
time: 9ms
memory: 7812kb
input:
3223 4143 3383 4499
output:
374776588
result:
wrong answer 1st numbers differ - expected: '139873119', found: '374776588'
Test #10:
score: 0
Time Limit Exceeded
input:
9257 3632 1736 9497
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
13657 8517 9780 16829
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
152794 105986 145639 8507
output:
result:
Test #13:
score: 0
Time Limit Exceeded
input:
2209 13866 42748 227
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
14279 7290 25915 2265
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
24703 6569 26356 26534
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
187348 185285 76358 13718
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
189507 133399 143282 13930
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
102698 162019 98595 137546
output:
result:
Test #19:
score: 0
Wrong Answer
time: 33ms
memory: 9276kb
input:
152381 90362 151048 15578
output:
987456777
result:
wrong answer 1st numbers differ - expected: '413943175', found: '987456777'
Test #20:
score: 0
Time Limit Exceeded
input:
34402 49259 74598 64198