Link game: 2019, Baidu Star · Programming Contest - preliminary round four
topic Link: HDU-6719 Strassen
C ++ did not write it
Then direct the Java
violence.
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))) ) );
}
}