是我记忆化搜索的练习题,结果本来打算写暴力看看分数,结果 AC 了?
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,p;
cin >> t >> p;
while(t--)
{
int x,y;
cin >> x >> y;
map<pair<int,int>,bool> mp;
int ans = 0;
while(true)
{
x = (x+y) % p;
if(x == 0)
{
ans = 1;
break;
}
if(mp.count({x,y}))
{
ans = 3;
break;
}
mp[{x,y}] = true;
y = (x+y) % p;
if(y == 0)
{
ans = 2;
break;
}
if(mp.count({x,y}))
{
ans = 3;
break;
}
mp[{x,y}] = true;
}
if(ans == 3)cout << "error\n";
else cout << ans << "\n";
}
return 0;
}
https://www.luogu.com.cn/record/196162466