by jai166 » Fri Aug 15, 2003 10:30 am
I've submited it many times, but it always says "Time Limit Exceeded"!
[c]/* 10268 */
#include<stdio.h>
#define MAX 1000000
#define MAX2 500000
unsigned int c2i(char c[],int in[]);
long double count(int x,int c[],unsigned int allc);
int pow(int x,unsigned int t);
void main(void)
{
char input[MAX];
unsigned int allc,i,j;
int c[MAX2],x;
while( scanf("%d\n",&x) ){
gets(input);
allc=c2i(input,c);
printf("%.0Lf\n",count(x,c,allc) );
}
}
unsigned int c2i(char input[],int in[])
{
unsigned int i=0,j=0;
int sum;
for(;input[i]; )
if(input[i]!='-'){ /*input>0*/
for(sum=0; input[i]!=' '&&input[i]!=0 ;i++){
sum*=10;
sum+=input[i]-48;
}
in[j++]=sum;
if(input[i])i++;
}else{/* input<0 */
for(i++,sum=0; input[i]!=' '&&input[i]!=0 ;i++){
sum*=10;
sum+=input[i]-48;
}
in[j++]=0-sum;
if(input[i])i++;
}
return j;
}
long double count(int x,int c[],unsigned int allc)
{
long double sum=0;
unsigned int i;
for(i=0;i<allc-1;i++)
sum+=(long double)(c[i]*(allc-i-1)*pow(x,allc-i-1-1));
return sum;
}
int pow(int x,unsigned int t)
{
int sum=1;
for(;t;t--)
sum*=x;
return sum;
}[/c]