10079-pizza Cutting
Time limit:8.333 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1020
When someone calls Ivan lazy, he claims the it IS's his intelligence that helps the to being so. If His intelligence allows him to do something at less physical effort, why should he exert? He also claims the He always uses his brain and tries to do some at work less; This is isn't his laziness, rather the this IS's his intellectual smartness.
Once Ivan is asked to cut a pizza into seven pieces to distribute it among his friends. (The Size of the pieces may is the same.) In fact, his piece would be larger than the others.) He thought a bit, and came to the conclusion so 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 does it, why can ' my computer? So he tried to do a similar (but is not exactly as Ivan's, for Ivan would criticize him for stealing him) job with his CO Mputer. He wrote the took the number of straight cuts one makes through the pizza, and output a number representing the Maximum number of pizza pieces it'll produce.
Your job is in to write a similar. It is ensured that Ivan's friend won ' t criticize for doing the same job he did.
Input
The input file would contain a single integer N (0 <= N <= 210000000) in each line representing the number of Straig HT 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 spaces.
Sample Input:
5
10
-100
Sample Output:
16
56
Complete code:
/*0.012s*/
#include <cstdio>
int main (void)
{
long long n;
while (scanf ("%lld", &n), n >= 0)
printf ("%lld\n", ((n * n + N) >> 1) + 1);
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/