Baidu Star 2019 · Programming Contest - preliminary round four 1001 Strassen

Link game: 2019, Baidu Star · Programming Contest - preliminary round four
topic Link: HDU-6719 Strassen

C ++ did not write it

Then direct the Javaviolence.

It seems to be used __int128.

import java.util.*;
import java.math.*;

public class Main {
    public static void main (String[] args) {
        Scanner in = new Scanner(System.in); 
        int T;
        T = in.nextInt();
        while(T > 0) {
            T--;
            BigInteger a, b, n;
            n = in.nextBigInteger();
            a = in.nextBigInteger();
            b = in.nextBigInteger();
            BigInteger ans = f(n, a, b);
            BigInteger mod = new BigInteger("1000000007");
            System.out.println(ans.remainder(mod));
        }
    }
    public static BigInteger f (BigInteger n, BigInteger a, BigInteger b) {
        BigInteger c = new BigInteger("18");
        BigInteger d = new BigInteger("7");
        BigInteger e = new BigInteger("2");
        if((n).equals(BigInteger.ONE)) {
            return b;
        }
        return ( ( (n.pow(3)).multiply(b) ).add( ((n.subtract(BigInteger.ONE)).multiply(n.pow(2))).multiply(a) ) ).min( ( (c.multiply( ((n.divide(e)).pow(2)) )).multiply(a) ).add( (d.multiply(f(n.divide(e), a, b))) ) );
    }
}

Guess you like

Origin www.cnblogs.com/wulitaotao/p/11409619.html