反思:
一开始看到想用大数,但是大数除法与大数取余我不会,就跳过了,结束了也没写。
后来试了试,暴力跑也有15分,所以下次太难的题目一定要去试一试暴力,那样也有分。
思路:
(1)JAVA大数
import java.util.*;
import java.math.*;
public class Main{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
BigInteger x = input.nextBigInteger();
BigInteger y = BigInteger.valueOf(1);
BigInteger li = BigInteger.valueOf(0);
BigInteger sh = BigInteger.valueOf(10);
BigInteger yi = BigInteger.valueOf(1);
int cnt=1;
while(true) {
BigInteger ans = y.mod(x);
if(ans.compareTo(li)==0) break;
y=y.multiply(sh);
y=y.add(yi);
cnt++;
}
x = y.divide(x);
System.out.print(x+" "+cnt);
}
}
(2)模拟竖式求商
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(void)
{
int n,i=1,x=1,y,t;
cin>>n;
while(x<n){
x=x*10+1; //被除数末尾添1,直到大于除数
i++;
}
while(1){
cout<<x/n; //输出商
x=x%n; //被除数更新为余数
if(x==0) break; //余数为0时结束
x=x*10+1; //余数末尾加一
i++;
}
cout<<" "<<i<<endl; //输出
return 0;
}