UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#206451#3165. 方程的解ZzhAllen100814ms2912kbC++111.4kb2024-07-22 18:58:182024-07-22 20:11:12

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
unordered_map<int,int> tot;
#define int long long
int a, b, p;
int qp(int a,int b,int p)
{
	int res = 1;
	while (b > 0)
      {
		if (b & 1) 
                  res = (res * a) % p;
		b = b >> 1;
            a = (a*a) % p;
	}
	return res;
}
int q;
int32_t main()
{
      ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
      cin >> q;
      while (q -- )
      {
            bool flag = false;
            cin >> p >> a >> b;
            if (b == 1)
            {
                  cout << "0\n";
                  continue;
            }
            int m = ceil(sqrt(1.0*p)*1.0);
            int idx = b;
            for (int i = 0; i < m; i ++ )
            {
                  tot[idx] = i;
                  idx = (idx * a) % p;
            } 
            int tmp = qp(a,m,p), t = 1;
            for (int i = 0; i <= m; i ++ )
            {
                  if (tot.find(t) != tot.end())
                        if (i*m >= tot[t]) 
                        {
                              cout << i * m - tot[t] << '\n';
                              flag = true;
                              break;
                        }
                  t = (t * tmp) % p;
            }
            if (!flag)
                  cout << "no solution" << '\n';
            tot.clear();
      }
      return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1272kb

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: 0ms
memory: 1272kb

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: 2ms
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: 133ms
memory: 2908kb

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: 111ms
memory: 2648kb

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: 106ms
memory: 2908kb

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: 123ms
memory: 2908kb

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: 122ms
memory: 2912kb

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: 108ms
memory: 2912kb

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: 109ms
memory: 2908kb

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