求n至少为多大时,n个1组成的数能被2013整除

 一开始的思路是s=s*10+1;但是会超出范围,所以把不用的(就是2013能整除的部分)减掉。于是语句改成下面的。

#include<iostream>
using namespace std;
int main()
{
	int s=1;
	int n=1;
	int m=10;
	while(s%2013)
	{
		n++;
		cout<<s<<endl;
		s=(s%2013)*10+1;
	}
		cout<<n;
}

猜你喜欢

转载自blog.csdn.net/weixin_43849266/article/details/100828025