#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, num = 1, len = 1;
cin >> x;
bool f = false;
while (num % x)
{
if (num / x || f) // 可能会出现1111000..111中间有0的情况,也得输出,当输出非前导零后,f置为true
cout << num / x, f = true;
num %= x;
num = num * 10 + 1, len++;
}
cout << num / x << ' ' << len;
return 0;
}
或
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x, num = 1, len = 1;
cin >> x;
while (num < x)
{
num = num * 10 + 1;
len++;
}
while (num % x)
{
cout << num / x;
num %= x;
num = num * 10 + 1, len++;
}
cout << num / x << ' ' << len;
return 0;
}