uva 10254 - The Priest Mathematician

1、初步计算,知道是大数

2、根据f[n]=min{2*(f[k]+2^(n-1-k)-1)+3};写了一个c++程序,打印出前面的解

3、在纸上比划找出规律

4、学习用java写大数

终于ac

java程序:

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

package pkg10254;



/**

 *

 * @author user

 */

import java.io.*;

import java.math.*;

import java.util.*;

import java.text.*;



public class Main

{

    static BigInteger[] f = new BigInteger[10001];

    public static void main(String[] args)

    {

        f[0] = BigInteger.valueOf(0);

        f[1] = BigInteger.valueOf(1);

        f[2] = BigInteger.valueOf(3);

        int i,j,k=2;

        BigInteger pow2=BigInteger.valueOf(2);

        for(i=2;i<10001;)

        {

            for(j=i;j<i+k&&j<10001;j++)

              f[j] = f[j-1].add(pow2);

            pow2=pow2.multiply(BigInteger.valueOf(2));

            i+=k;

            k++;

        }

        Scanner cin = new Scanner (new BufferedInputStream(System.in));

        int n;

        while(cin.hasNext())

        {

            n=cin.nextInt();

            System.out.println(f[n]);

        }

    }

}

  

你可能感兴趣的:(Math)