FOJ1084 Three powers(高精度)

FOJ1084 Three powers(高精度)

http://acm.fzu.edu.cn/problem.php?pid=1084
a[n]> Sa[i](i<n), f[n]=f[n-1]*2前n个数共有2^n种,然后java即可(NetBeans,赞!)
import  java.util. * ;
import  java.math.BigInteger;
public   class  Main
{
    
public static void main(String[] args) 
    
{
        Scanner cin
=new Scanner(System.in);
        BigInteger num;
        
int[] res=new int[100];
        
int len;
        
while(cin.hasNextBigInteger())
        
{
            num
=cin.nextBigInteger();
            
if(num.signum()==0break;
            num
=num.subtract(BigInteger.valueOf(1));
            
if(num.signum()==0)
            
{
                System.out.println(
"{ }");
                
continue;
            }

            len
=0;
            
while(num.bitLength()>0)
            
{
                res[len
++]=num.bitLength();
                num
=num.clearBit(res[len-1]-1);
            }

            System.out.print(
"{");
            
for(int i=len-1;i>0;i--)
                 System.out.print(
" "+BigInteger.valueOf(3).pow(res[i]-1)+",");
            System.out.println(
" "+BigInteger.valueOf(3).pow(res[0]-1)+" }");
        }

    }

}

你可能感兴趣的:(FOJ1084 Three powers(高精度))