题目解析
找到一个最小的数 使其与给定数 相乘 获得一个全是1的数
解题思路
java大数硬模
java 真香
或者
直接依据下图模拟

我们能发现在除法运算的时候 我们总是将余数与后面的所有数组成一个新的数再次进行除法运算
所以这就我们的关键 每次将余数拿出来 看是否为 0 如果为 0 了(也就是1...1的倍数了) 那就可以不需要再继续往下枚举了
否则达不到要求 需要接着往下枚举
(注: 我们需要看最前面的一部分一定要比n大 后面的无所谓。
如果还是有点不明白可以试试 111 / 20 是怎么样子的)
代码
大数
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
BigInteger zero = BigInteger.valueOf(0);
BigInteger one = BigInteger.valueOf(1);
BigInteger ten = BigInteger.valueOf(10);
BigInteger x = sc.nextBigInteger();
BigInteger mul = BigInteger.valueOf(1);
while (mul.mod(x).compareTo(zero) != 0)
mul = mul.multiply(ten).add(one);
out.println(mul.divide(x) + " " + mul.toString().length());
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}
除法枚举
import java.io.*;
import java.math.*;
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int n = sc.nextInt();
long mul = 0;
boolean f = true;
for (int len = 0;; len++)
{
mul = mul * 10 + 1;
if (mul >= n)
f = false;
if (!f)
out.print(mul / n);
mul = mul % n;
if (mul == 0)
{
out.println(" " + (len + 1));
break;
}
}
out.flush();
out.close();
}
static Scanner sc = new Scanner(System.in);
static PrintWriter out = new PrintWriter(System.out);
}