【实例描述】

  爱因斯坦问题是假设某人走一个台阶,如果每步走两级,最后只剩一级,如果每步走三级,最后剩两级,如果每步走四级,最后剩三级,如果每步走五级,最后剩四级,如果每步走六级,最后剩五级,如果每步走七级,则一个也不剩。本实例求出1000以内符合该条件的数字。

【实现过程】

  本实例抽象为数学问题是:总的台阶数分别对2、3、4、5、6、7取余的结果是1、2、3、4、5、0。

代码如下:

#include<iostream>
using namespace std;
bool Is_right(int n)
{
	for(int i=1;i<7;i++)
	{
		if(i==6)
		{
			if(n%(i+1)!=0)
				return false;
		}
		else
		{
			if(n%(i+1)!=i)
				return false;
		}
	}
	return true;
}
void main()
{
	cout<<"---------爱因斯坦台阶-----------"<<endl;
	cout<<"1000以内属于爱因斯坦台阶数字为:"<<endl;
	int max=1000;
	while(max)
	{
		if(!Is_right(max))
		{}
		else
			cout<<max<<end;
		max--;
	}
}

 

相关文章:

  • 2021-07-12
  • 2022-01-01
  • 2021-12-12
  • 2021-07-03
  • 2021-12-30
  • 2022-01-25
  • 2021-08-05
猜你喜欢
  • 2022-12-23
  • 2021-11-26
  • 2022-12-23
  • 2021-06-13
  • 2021-12-28
  • 2021-07-27
  • 2022-12-23
相关资源
相似解决方案