将一个数字尽可能多分成3相乘的形式,余下来的乘2,注意ans会超过longlong,我用的java
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args)
{
// your code goes here
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n =sc.nextInt();
if(n==1){System.out.println(1);continue;}
if(n==2){System.out.println(2);continue;}
int cnt1=n/3;int cnt2=n%3;
BigInteger ans=new BigInteger("1");
if(n>=3)
{
BigInteger b=new BigInteger("3");
BigInteger c=new BigInteger("2");
BigInteger e=new BigInteger("4");
if(cnt2==2||cnt2==0)
{
for(int i=1;i<=cnt1;i++)
ans=ans.multiply(b);
if(cnt2==2) ans=ans.multiply(c);
}
else
{
for(int i=1;i<cnt1;i++)
ans=ans.multiply(b);
ans=ans.multiply(e);
}
}
System.out.println(ans);
}
}
}