Sawtooth
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 422 Accepted Submission(s): 134
● 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 ?
Each case contains one single non-negative integer, indicating number of “M”s. (0 ≤ N ≤ 1012)
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.
1
2
Case #2: 19
#include<cstdio>
#include<cstring>
char aa[],bb[];
int ans[];
int mul( char *a, char *b, int temp[])
{ int i,j,la,lb,l;
la=strlen(a);
lb=strlen(b); for ( i=;i<la+lb;i++ )
temp[i]=;
for ( i=;i<=la-;i++ ) {
l=i;
for ( j=;j<=lb-;j++ ) {
temp[l]=(b[j]-'')*(a[i]-'')+temp[l];
l++;
}
}
while ( temp[l]== )
l--;
for ( i=;i<=l;i++ ) {
temp[i+]+=temp[i]/;
temp[i]=temp[i]%;
}
if ( temp[l+]!= )
l++; while ( temp[l]/!= ) {
temp[l+]+=temp[l]/;
temp[l]=temp[l]%;
l++;
}
if ( temp[l]== )
l--;
return l;
}
void cal(__int64 a,char *str)
{
int i=;
while(a>)
{
str[i++]=(a%)+'';
a/=;
}
}
int main()
{
int cas;
__int64 n;
scanf("%d",&cas);
for(int i=;i<=cas;i++)
{
scanf("%I64d",&n);
printf("Case #%d: ",i);
if(n==)printf("1\n");
else
{
memset(aa,'\0',sizeof(aa));
memset(bb,'\0',sizeof(bb));
memset(ans,,sizeof(ans));
//,(8*n-7)*n+1
cal(*n-,aa);
cal(n,bb);
int len=mul(aa,bb,ans);
ans[]++;
int c=;
for(int j=;j<=len;j++)
{
ans[j]+=c;
if(ans[j]>)
{
c=ans[j]/;
ans[j]%=;
}
}
if(c>)
printf("%d",c);
for(int j=len;j>=;j--)
printf("%d",ans[j]);
printf("\n");
}
}
return ;
}