ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#206481 | #3165. 方程的解 | 18915523188 | 100 | 11242ms | 3228kb | C++11 | 946b | 2024-07-22 19:42:32 | 2024-07-22 20:15:16 |
answer
#include <bits/stdc++.h>
#define ll long long
#define N 1145141919810
using namespace std;
ll T,a,b,p,m,t,tx,ans,x;
multimap<ll,ll> ma;
multimap<ll,ll>::iterator iter;
ll f(ll x,ll q){
ll ans=1;
while(q){
if(q&1) ans*=x;
ans%=p;
q>>=1;
x*=x;
x%=p;
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin>>T;
while(T--){
cin>>p>>a>>b;
m=sqrt(p);
if(m*m!=p) m++;
ans=N;
for(ll i=0;i<=m;i++){
t=(f(a,i)*b)%p;
ma.insert(pair<ll,ll>(t,(ll)i));
}
for(ll i=0;i<=m;i++){
t=f(a,i*m)%p;
if(ma.count(t)){
auto beginItr = ma.lower_bound(t);
auto endItr = ma.upper_bound(t);
for (auto iter = beginItr; iter != endItr; ++iter){
x=i*m-iter->second;
if(x<0) continue;
ans=min(ans,x);
}
}
}
ma.clear();
if(ans==N){
cout<<"no solution"<<endl;
continue;
}
cout<<ans<<endl;
}
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 5ms
memory: 1268kb
input:
40 38371 30278 12451 51949 1925 16824 39727 8424 23446 35729 8604 4699 48221 3464 35984 99961 3104 7...
output:
no solution 12246 no solution 26865 5259 53994 no solution no solution no solution 62082 34527 no so...
result:
ok 40 lines
Test #2:
score: 10
Accepted
time: 7ms
memory: 1268kb
input:
40 59797 57209 1596 88771 8724 31857 1409 750 657 92669 11315 62 35809 28252 29433 9433 6982 6988 71...
output:
no solution 17394 187 no solution no solution no solution 10863 5469 no solution no solution 11450 1...
result:
ok 40 lines
Test #3:
score: 10
Accepted
time: 4ms
memory: 1268kb
input:
40 27737 16262 21614 74101 65654 72418 95063 80940 29105 37171 6120 13141 59467 6421 48202 67523 125...
output:
2442 no solution 18376 16604 no solution 9491 28584 32526 61895 81785 1498 3972 36718 no solution 25...
result:
ok 40 lines
Test #4:
score: 10
Accepted
time: 1815ms
memory: 3228kb
input:
40 701007721 226836410 700221467 609376637 555505065 537110248 718126649 27666056 209669407 72722314...
output:
661928284 no solution no solution no solution 176718 no solution no solution 44398418 202453465 3013...
result:
ok 40 lines
Test #5:
score: 10
Accepted
time: 1702ms
memory: 3224kb
input:
40 998347159 951648148 222699374 265346579 170041583 1651913 854282311 697467218 708280399 593929477...
output:
221559601 236087167 180546784 no solution 178292130 788810105 471022049 111588212 26971634 no soluti...
result:
ok 40 lines
Test #6:
score: 10
Accepted
time: 1604ms
memory: 3224kb
input:
40 508928911 368260395 197014976 467174443 20166302 457682957 633266987 365520218 142332172 99393132...
output:
78428882 no solution 126879376 282180619 212652957 no solution no solution 71081001 no solution no s...
result:
ok 40 lines
Test #7:
score: 10
Accepted
time: 1431ms
memory: 3224kb
input:
40 566551577 461319 143876378 626673361 94961490 614207471 319184081 208898009 250733304 79134857 67...
output:
42699350 no solution no solution 31308962 no solution 75601139 2556315 no solution 108622155 5470549...
result:
ok 40 lines
Test #8:
score: 10
Accepted
time: 1474ms
memory: 3192kb
input:
40 781753457 121430598 605906664 611135243 389418731 471876973 43073521 11878623 36994297 600303173 ...
output:
476544225 59696004 13371203 103927676 no solution 212232978 no solution 8137839 no solution 7640582 ...
result:
ok 40 lines
Test #9:
score: 10
Accepted
time: 1749ms
memory: 3188kb
input:
40 558435851 475491008 117732431 855534541 258937944 550324527 786565141 437830687 631195882 9550869...
output:
96234018 no solution no solution 828878625 608502042 no solution no solution no solution 13898141 no...
result:
ok 40 lines
Test #10:
score: 10
Accepted
time: 1451ms
memory: 3220kb
input:
40 195720619 179620823 21069142 271820323 34487272 246686683 529565051 417816976 185673874 974626363...
output:
4939877 92699274 no solution no solution no solution 245484712 532725991 706946635 no solution no so...
result:
ok 40 lines
Extra Test:
score: 0
Extra Test Passed