2021年-PTA模拟赛-L1-7 整除光棍(C/C++思路)
思路:
在L1里面,那就不考虑大数运算了,列个竖式发现只需要每次得到除数之后输出,然后把余数乘10加1就可以进行下一轮运算了...15行搞定~
为什么说c/c++思路呢————java自带高精度运算,应该十行左右就可以搞定了。
AcCode:
#include<bits/stdc++.h>
using namespace std;
int main(){
int x, t = 0, cnt = 0;
cin >> x;
while(t < x) t = t * 10 + 1, cnt++;
while(true){
cout << t / x;
if(t % x == 0) break;
t = (t % x * 10) + 1;
cnt++;
}
cout << " " << cnt;
return 0;
}