记忆化搜索?这能切?
查看原帖
记忆化搜索?这能切?
1120417
douhuazhenren1楼主2024/4/30 09:44
#include<iostream>
#include<cstdio>
using namespace std;
int x,y,t,p,flag;
long long s;
int main()
{
	// freopen("b.in","r",stdin);
	// freopen("b.out","w",stdout);
	cin>>t>>p;
	s=2500000/t;
	while(t--)
	{
		cin>>x>>y;
		for(int i=1;i<=s;i++)
		{
			x=(x+y)%p;
			if(x==0)
			{
				flag=1;
				break;
			}
			y=(x+y)%p;
			if(y==0)
			{
				flag=2;
				break;
			}
		}
		if(flag)
			cout<<flag<<endl;
		else
			cout<<"error"<<endl;
		flag=0;
	}
	// fclose(stdin);
	// fclose(stdout);
	return 0;
}
2024/4/30 09:44
加载中...