⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 自守数.cpp

📁 八皇后问题的最好解法,利用回朔法的典型例子,还有其他几个好程序
💻 CPP
字号:
#include <iostream.h>              //只求10--200000
void main()
{
	int n,m,i,j,temp;
L:cout<<"Please input the min:"<<endl;
    cin>>n;
	cout<<"Please input the max:"<<endl;
	cin>>m;
	if(n<10||m>200000||n>=m)goto L;

	i=n;
	j=0;
	cout<<n<<"与"<<m<<"之间的自守数有:"<<endl;
	do{
	if(i<=99)
	{
		temp=(i*i)%100;
		if(temp==i){cout<<i<<"     ";j++;}
	}
	else if(i>=100&&i<=999)
	{
		temp=(i*i)%1000;
		if(temp==i){cout<<i<<"     ";j++;}
	}
	else if(i>=1000&&i<=9999)
	{
		temp=(i*i)%10000;
		if(temp==i){cout<<i<<"     ";j++;}
	}
	else if(i>=10000&&i<=99999)
	{
		temp=(i*i)%100000;
		if(temp==i){cout<<i<<"     ";j++;}
	}
	else if(i>=100000&&i<=200000)
	{
		temp=(i*i)%100000;
		if(temp==i){cout<<i<<"     ";j++;}
	};
	if(j!=0&&j%5==0)cout<<endl;
	i++;

}while(i<m);
    cout<<endl;
}            //这个程序溢出了

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -