#include<string>
#define max 3000
using namespace std;
int main()
{
int result[max];
int a, b, m;
cin >> a >> b;
m = a%b;
for (int i = 0; i != 3000; i++){//模仿除法笔算,记录小数部分3000位
m *= 10;
result[i] = m / b;
m = m%b;
}
int length = 0;
while (result[length] >=0){//没有记录的位数都是-**********
length++;
}
bool flag = true;
int time;
for ( time = 1; time<3000; time++)//枚举周期
{
for (int j = time; j != length; j++)
{
if (result[j] != result[j%time])
{
flag = false;
break;
}
if (j == length-1)
flag = true;
}
if (flag)
{
cout << "小数循环了" << time << "位" << endl;
break;
}
}
cout << "0.";
for (int i = 0; i != time; i++)
cout << result[i];
system("pause");
return 0;
}
Uva 202
最新推荐文章于 2022-01-04 17:22:29 发布