How Many Pieces of Land? Euler's Theorem

Source: Internet
Author: User

How Many Pieces of Land? Euler's Theorem


Euler's theorem 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 chooseNArbitrary points on its boundary. Then you connect all these points with one another with straight lines (that'sN * (n-1)/2ConnectionsNPoints). 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 integerS (0 <S <3500), Which indicates how many sets of input are there. The nextSLines containSSets of input. Each input contains one integerN (0 <= N <2 ^ 31) <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Signature + signature + CjQ8YnI + CjE8YnI + CjI8YnI + CjM8YnI + CjQ8YnI + signature + IDwvcD4KPHA + Signature = "2" width = "100% ""align =" center ">

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();    }}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.