Pizza cutting for the provincial AK exercise Competition

Source: Internet
Author: User

Original question:

Description

Problem E

Pizza Cutting

Input:Standard Input

Output:Standard output

 

When someone CILS Ivan lazy, he claims that it is his intelligence that helps him to be so. If his intelligence allows him to do something at less physical effort, why showould he exert more? He also claims that he always uses his brain and tries to do some work at less effort; this is not his laziness, rather this is his intellectual smartness.

Once Ivan was asked to cut a pizza into seven pieces to distribute it among his friends. (size of the pieces may not be the same. in fact, his piece will be larger than the others .) he thought a bit, and came to the conclusion that he can cut it into seven pieces by only three straight cuts through the pizza with a pizza knife. accordingly, he cut the pizza in the following way (guess which one is Ivan's piece ):

 

One of his friends, who never believed in Ivan's smartness, was startled at this intelligence. He thought, if Ivan can do it, why can't my computer? So he tried to do a similar (but not exactly as Ivan's, for Ivan will criticize him for stealing his idea) job with his computer. he wrote a program that took the number of Straight cuts one makes through the pizza, and output a number representing the maximum number of pizza pieces it will produce.

Your job here is to write a similar program. It is ensured that Ivan's friend won't criticize you for doing the same job he did.

 

Input

The input file will contain in a single integer N (0 <= n <= 210000000) in each line representing the number of straight line cuts one makes through the pizza. A negative number terminates the input.

 

Output

Output the maximum number of pizza pieces the given number of cuts can produce. Each line shoshould contain only one output integer without any leading or trailing space.

 

Sample input:

5
10
-100

 

Sample output:

16
56

 

Analysis:

It is the minimum number of knives and the most Cut pie ~~~~ Remember the formula-P (minimum number of knives, number of slices with the most cut) = n × (n + 1)/2 + 1

Original code:

#include<stdio.h>int main(){    long long n;    while(scanf("%lld",&n) && n>=0)    {        printf("%lld\n",n*(n+1)/2+1);    }    return 0;}

 

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.