Skip to main content

UVa 10079 - Pizza Cutting Solution

UVa 10079 - Pizza Cutting


Description: 

When someone calls 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 should 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 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 should
contain only one output integer without any leading or trailing space.

Sample Input

5
10
-100

Sample Output

16
56

Solution

#include<stdio.h>
int main()
{
    long long n,x;
    int i;
    while(1)
    {
        scanf("%lld",&n);
        x=1;
        if(n<0)
            break;
        else if(n==0)
        {
            printf("%lld\n",x);
            continue;
        }
        for(i=1;i<=n;i++)
            x=(i*2)+(x-i);
        printf("%lld\n",x);
    }
    return 0;
}



See More Solution:

Comments

Populer Article

UVa 10082 - WERTYU Solution

UVa  10082 - WERTYU Description:   A common typing error is to place the  hands on the keyboard one row to the  right of the correct position. So ‘Q’ is  typed as ‘W’ and ‘J’ is typed as ‘K’ and  so on. You are to decode a message typed in this manner. Input Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except  Q, A, Z), or punctuation shown above [except back-quote (‘)]. Keys labelled with words [Tab, BackSp,  Control, etc.] are not represented in the input. Output You are to replace each letter or punction symbol by the one immediately to its left on the ‘QWERTY’  keyboard shown above. Spaces in the input should be echoed in the output. Sample Input O S, GOMR YPFSU/ Sample Output I AM FINE TODAY.  Solution #include<stdio.h> int main () { char str[10000], key[]={'`','1','2','3','4','5','6','7','8','9','0', '-','=','...

UVa 10062 - Tell me the frequency Solution

UVa  10062 - Tell me the frequency Description:  Given a line of text you will have to find out the frequencies of the ASCII characters present in it. The  given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with  \n and \r but always keep those out of consideration. Input Several lines of text are given as input. Each line of text is considered as a single input. Maximum  length of each line is 1000. Output Print the ASCII value of the ASCII characters which are present and their frequency according to the  given format below. A blank line should separate each set of output. Print the ASCII characters in the  ascending order of their frequencies. If two characters are present the same time print the information  of the ASCII character with higher ASCII value first. Input is terminated by end of file. Sample Input AAABBC 122333 Sample Output 67 1 66 2 65 3 49 1 50 2 51 3 Solution #include<stdio.h...