自守数.cpp
来自「八皇后问题的最好解法,利用回朔法的典型例子,还有其他几个好程序」· C++ 代码 · 共 45 行
CPP
45 行
#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 + =
减小字号Ctrl + -
显示快捷键?