解题思路,通过模拟除法来做
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
int n = 0;
int tmp = 1;
cin >> x;
string num;
while (tmp < x) {
tmp = tmp*10 + 1;
n++;
}
while (tmp % x != 0) {
num += tmp/x+'0';
n++;
tmp = tmp%x*10 + 1;
}
num += tmp/x + '0';
n++;
cout<<num<<" "<<n;
}
运行结果: