观察题目,易得出暴力代码,但是会TLE,只能得20pts

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 int T;
 5 ll a, b, x1, t, p, ans;
 6 int main()
 7 {
 8     scanf("%d", &T);
 9     while(T--)
10     {
11         ans = 0;
12         scanf("%lld %lld %lld %lld %lld", &p, &a, &b, &x1, &t);
13         while(233)
14         {
15             ++ans;
16             if(ans > p)
17             {
18                 puts("-1");
19                 break;
20             }
21             if(x1 == t)
22             {
23                 printf("%lld\n", ans);
24                 break;
25             }
26             x1 = (x1 * a + b) % p;
27         }
28     }
29     return 0;
30 }
View Code

相关文章:

  • 2021-12-10
  • 2022-02-18
  • 2021-08-17
  • 2022-12-23
  • 2021-07-16
  • 2021-09-19
  • 2022-12-23
  • 2021-10-06
猜你喜欢
  • 2021-11-30
  • 2021-06-01
  • 2021-11-30
  • 2021-11-30
  • 2021-11-05
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案