求能卡住我代码的样例
查看原帖
求能卡住我代码的样例
226167
呆呆的她啊楼主2023/11/9 20:57
#include<iostream>
using namespace std;
int t,p; int flag=0;
int x,y;
void df(int a,int b,int step)
{  if(step>=10000)return;
	if(step%2==1)
	{ 
		a=(a+b)%p;
		if(a==0)
		{cout<<1<<endl;
			flag=1;
			return ;
		}
		
		else
		//	cout<<"a="<<a<<endl;
			df(a,b,step+1);

	}
	if(step%2==0)
	{b=(a+b)%p;
		if(b==0)
		{cout<<2<<endl;
			flag=1;
			return ;
		}
		
		else
			//cout<<"b="<<b<<endl;
			df(a,b,step+1);	
	}
	return ;
}
int main()
{
	
	cin>>t>>p;
	for(int i=1;i<=t;i++)
	{
		cin>>x>>y;
		df(x,y,1);if(flag==0)cout<<"error"<<endl;
	}	
	
	
	
	
	
	
	
	
	
	
	
	
	return 0;
}
2023/11/9 20:57
加载中...