题目大意:给一个数n,找出一个各位全是1的最小的十进制数,使得n能整除这个数。只输出最小位数。
题目分析:纯粹是数论,暴力。
代码如下:
# include<iostream> # include<cstdio> # include<cstring> # include<algorithm> using namespace std; int solve(int n) { int cnt=0; unsigned long long x=0; while(1){ x=(x%n)*(10%n)+1; x%=n; ++cnt; if(x==0) return cnt; } } int main() { int n; while(scanf("%d",&n)!=EOF) { printf("%d ",solve(n)); } return 0; }