Input

Output 每组数据输出一行，包含一个整数表示答案模109+7的余数。

Sample Input
1
16 1 1

Sample Output
7872

``````#include <bits/stdc++.h>
#define _int __int128

using namespace std;

{
_int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}

inline void write(_int x)
{
if(x<0)
{
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}

_int cf(_int n, _int a, _int b)
{
_int s1=n*n*n*b+(n-1)*n*n*a;
if(n%2)
{
return s1;
}
_int s2=18*(n/2)*(n/2)*a+7*cf(n/2, a, b);

return min(s1, s2);
}

int main()
{
int t;
scanf("%d", &t);
while(t--)
{
write(cf(n, a, b)%1000000007);
printf("\n");
}

return 0;
}
``````
``````import java.math.BigInteger;
import java.util.Scanner;

public class Main {

static BigInteger cf(BigInteger n, BigInteger a, BigInteger b) {

if(n.equals(BigInteger.ONE)) {

return s1;
}

return s1.min(s2);
}

public static void main(String []args) {

Scanner cin=new Scanner(System.in);
int t;
t=cin.nextInt();
while(t-->0) {

BigInteger n, a, b;

n=cin.nextBigInteger();
a=cin.nextBigInteger();
b=cin.nextBigInteger();

System.out.println(cf(n, a, b).remainder(new BigInteger("1000000007")));
}
}
}
``````