UVA 10213 How Many Pieces of Land? 歐拉定理,10213pieces

來源:互聯網
上載者:User

UVA 10213 How Many Pieces of Land? 歐拉定理,10213pieces


歐拉定理 V-E+F=C+1


Problem G
How Many Pieces of Land?
Input: Standard Input
Output: Standard Output
Time Limit: 3 seconds

 

You are given an elliptical shaped land and you are asked to choose n arbitrary points on its boundary. Then you connect all these points with one another with straight lines (that’s n*(n-1)/2 connections for n points). What is the maximum number of pieces of land you will get by choosing the points on the boundary carefully?

 


Fig: When the value of n is 6.

 

Input

The first line of the input file contains one integer S (0 < S < 3500), which indicates how many sets of input are there. The next S lines contain S sets of input. Each input contains one integer N (0<=N<2^31).

 

Output

For each set of input you should output in a single line the maximum number pieces of land possible to get for the value of N.

 

Sample Input:

4
1
2
3
4

 

Sample Output:

1
2
4
8

Shahriar Manzoor



/** * Created by ckboss on 15-2-1. */import java.math.BigInteger;import java.util.*;public class Main {    BigInteger pfh(BigInteger n){        return n.multiply((n.add(BigInteger.ONE))).multiply((n.multiply(BigInteger.valueOf(2))).add(BigInteger.ONE)).divide(BigInteger.valueOf(6));    }    BigInteger getV(BigInteger n){        BigInteger A = n.subtract(BigInteger.valueOf(2));        BigInteger B = n.subtract(BigInteger.valueOf(3));        BigInteger temp = A.multiply(B).divide(BigInteger.valueOf(2)).multiply(A).subtract(pfh(B));        temp = temp.multiply(n).divide(BigInteger.valueOf(4));        return temp.add(n);    }    BigInteger getE(BigInteger n){        BigInteger A = n.subtract(BigInteger.valueOf(2));        BigInteger B = n.subtract(BigInteger.valueOf(3));        BigInteger temp = A.multiply(B).divide(BigInteger.valueOf(2)).multiply(A).subtract(pfh(B)).add(n).subtract(BigInteger.ONE);        temp = temp.multiply(n).divide(BigInteger.valueOf(2));        return temp.add(n);    }    Main(){        Scanner in = new Scanner(System.in);        int T_T = in.nextInt();        while(T_T-->0) {            BigInteger n = in.nextBigInteger();            BigInteger V = getV(n);            BigInteger E = getE(n);            BigInteger F = BigInteger.ONE.subtract(V).add(E);            System.out.println(F);        }    }    public static void main(String[] args){        new Main();    }}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.