标题:复数幂

public class demo5 {

    public static void main(String[] args) {
        try {
            PrintStream ps = System.out;
            PrintStream prs = new PrintStream(new File("C:\\Users\\Laptop\\Desktop\\ans\\ans.txt"));
            System.setOut(prs);
            work(123456);
            System.setOut(ps);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    private static void work(int n) {
        BigInteger x = BigInteger.valueOf(2);
        BigInteger y = BigInteger.valueOf(3);

        for (int i = 1; i < n; i++) {
            BigInteger tmp1 = x.multiply(BigInteger.valueOf(2)).subtract(y.multiply(BigInteger.valueOf(3)));
            BigInteger tmp2 = x.multiply(BigInteger.valueOf(3)).add(y.multiply(BigInteger.valueOf(2)));

            x = tmp1;
            y = tmp2;
        }
        System.out.println(x + "" + y + "i");// 输出结果
    }
}

划重点,这个输出到文件代码要记。

posted @ 2019-10-25 19:29  hardhp74520  阅读(265)  评论(0编辑  收藏  举报