2019 年百度之星·程序设计大赛 - 初赛四 1001 Strassen

比赛链接:2019 年百度之星·程序设计大赛 - 初赛四
题目链接:HDU-6719 Strassen

C++ 没写出来

于是直接上 Java 暴力。

好像可以用 __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))) ) );
    }
}

猜你喜欢

转载自www.cnblogs.com/wulitaotao/p/11409619.html
今日推荐