​点击打开链接​

Sawtooth

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2467    Accepted Submission(s): 911


Problem Description

Think about a plane:


● One straight line can divide a plane into two regions.

● Two lines can divide a plane into at most four regions.

● Three lines can divide a plane into at most seven regions.

● And so on...


Now we have some figure constructed with two parallel rays in the same direction, joined by two straight segments. It looks like a character “M”. You are given N such “M”s. What is the maximum number of regions that these “M”s can divide a plane ?


hdu 5047 Sawtooth_#include

 


Input

The first line of the input is T (1 ≤ T ≤ 100000), which stands for the number of test cases you need to solve.

Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 10 12)

 


Output

For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then an integer that is the maximum number of regions N the “M” figures can divide.

 


Sample Input

2 1 2

 


Sample Output

Case #1: 2 Case #2: 19

题意:

 n条M型折线可以把空间最多分成多少块,可以设ax^2+bx+c,解方程,得出规律8n(n-1)+1+n;因为超出long long,所以分开求。听了他们讨论的,总结一下。

#include<cstdio>
#include<cmath>
#include<cstdlib>
#define ll __int64
int main()
{
ll n;
ll t,ca=1;
scanf("%I64d",&t);
while(t--)
{
scanf("%I64d",&n);
__int64 p1=(8*n)%1000000;
__int64 p2=(8*n)/1000000;
__int64 ap1=p1*(n-1)+1+n;
__int64 ap2=p2*(n-1);
ap2+=ap1/1000000;
ap1%=1000000;
printf("Case #%I64d: ",ca++);
if(ap2)
printf("%I64d%06I64d\n",ap2,ap1);
else
printf("%I64d\n",ap1);
}
return 0;
}