Sol.UVA10127

发布时间 2023-09-12 19:10:09作者: JacoAwA

题意:给定 \(n\),找到形如 \(1111...1111\) 的数 \(y\),使得 \(y \equiv 1\mod x\),最终输出 \(y\) 的位数。

思路:形如 \(1111...1111\) 的数可以拆分成 \(10...00 \times 1 +10...0 \times 1 + ... + 10 \times 1 + 1\),因此我们可以每次让 $y=y \times 10 + y $,每次判断是否能整除 \(n\),并且累加答案,如果可以整除就输出答案。

代码如下:

#include<iostream>
using namespace std;
int n;
int main(){
	while(cin>>n){
		int ans=1,y=1;
		while(y){
			y=(y*10+1)%n;
			ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}