## 10268 - 498'

Moderator: Board moderators

I didn't find any wrong with this problem.

You have to careful about the intermediate calcualtions. Although the problem description says that the output will fit in 32 bit integer, but the intermediate values may be larger than that. So, use Horner's rule to evaluate the derivative of polynomial . Also, careful about the input processing. I used gets() to take the input and strtok() to separate the coefficients.

Code: Select all
`char buf[1000000];int main(){                // declare variables   while (gets(buf))   {      sscanf(buf, "%ld", &x);      px = 0;      ppx = 0;      gets(buf);      ptr = strtok(buf, " \n");      while (ptr)      {         a = atol(ptr);         ppx = ppx * x + px;         px = px * x + a;         ptr = strtok(NULL, " \n");      }      // print ppx   }   ...}`
IIUC GOLD
New poster

Posts: 19
Joined: Tue Jun 11, 2002 4:27 pm

To IIUC GOLD:

Thx for your help!! I rewrite my code and got AC!
tacolin
New poster

Posts: 2
Joined: Tue Feb 10, 2004 2:24 pm

### 10268

Hi I got WA, I used honor's rule and used long long data type....what i can do more? what will be the array limit?
Code: Select all
`#include<cstdio>#include<cstring>long long a[3000000];int main(){   long long x,sum,i,j,n;   char temp[3000000],*ptr;   while(scanf("%lld",&x)==1)   {      getchar();      gets(temp);      ptr=strtok(temp," ");      i=0;      while(ptr)      {         sscanf(ptr,"%lld",&a[i++]);         ptr=strtok(NULL," ");      }      i--;      n=i;      for(j=0;j<i;j++)      {         a[j]*=n--;      }      sum=a[0];      for(j=1;j<i;j++)      {         sum=sum*x+a[j];      }      printf("%lld\n",sum);   }   return 0;}`
Jalal : AIUB SPARKS

CodeMaker
Experienced poster

Posts: 183
Joined: Thu Nov 11, 2004 12:35 pm

As a matter of fact, you don't need any arrays or whatever in this problem.

A hint: the "definition" of derivative given in the statement is not the best way to proceed. Remember the product rule of differentiation: d(uv) = du v + u dv. Using it and Horner's method you can avoid arrays.

long long was enough in my solution.
mf
Guru

Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland

### 10268-WA

i always got WA. help me plz.
Code: Select all
`#include<stdio.h>#include<math.h>int main(void){    int i,j,x,l;    static int c[2000000];    long long sum;    char flag;    while(scanf("%d",&x)!=EOF)    {        i=0;        while(scanf("%d%c",&c[i],&flag)!=EOF)        {            if(flag=='\n')break;            i++;        }        sum=0;        for(j=i;j>0;j--)            sum+=c[i-j]*j*pow(x,j-1);        printf("%lli\n",sum);    }    return 0;}`
lyc
New poster

Posts: 2
Joined: Fri Jun 17, 2005 8:30 am

### 10268 (498') got WA!

It seems that my program works ok with all the cases i can figure out , but i consistently get WA !
Maybe some good guy can help me with it~

Code: Select all
`#include <stdio.h>#include <iostream>#include <stdlib.h>#include <string.h>#include <math.h>using namespace std;int main(){    int x;    char a[1000000],*p;    int num[1000],i,n,j;    while(scanf("%d\n",&x)==1)    {        long total = 0;        gets(a);        p = strtok(a," ");        num[0] = atoi(p);        for(p=strtok(NULL," "),i=1; p!=0; p=strtok(NULL," "),i++)                num[i] = atoi(p);                for(j=0;j<i;j++)                num[j] *= i-j-1;                        for(j=0;j<i-1;j++)                         total += num[j] * static_cast<long>(pow((double)x,(double)i-j-2));                 printf("%ld\n",total);                       }            }`
liqu
New poster

Posts: 2
Joined: Thu Aug 25, 2005 6:50 pm

### 10268 - WA :(

It seems that my program works ok with all the cases i can figure out , but i consistently get WA !

program P10268;
var A,X,C,j:integer;
S:string;
Sum:LongInt;
begin
while not EOF do
begin
j:=0;
Sum:=0;
for C:=0 to Length(S) do
if S[C]=' ' then j:=j+1;
while j>0 do
begin
if POS(' ',S)>0 then
begin
VAL(COPY(S,1,POS(' ',S)-1),A,C);
DELETE(S,1,POS(' ',S));
Sum:=Sum+A*j*Round(Exp((j-1)*Ln(X)));
end;
j:=j-1;
end;
WriteLn(Sum);
end;
end.
New poster

Posts: 1
Joined: Sun Nov 13, 2005 8:49 pm

### 10268 - 498'

I got RTE.. but I don't see why..~!
Somebody please tell me why.. ~

Code: Select all
`CUT AFTER AC`

Thanks..
Last edited by helloneo on Fri Jun 08, 2007 6:28 am, edited 1 time in total.
helloneo
Guru

Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Use buf size 1000001 and coef size 400000. I think these are the reasons for which you are getting RTE.

Hope it helps.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

### int & long long

I use int and got AC
But long long results in WA.
Who can explain why?
handsomepot
New poster

Posts: 5
Joined: Sun Jul 08, 2007 12:15 pm

hi, I try this problem, but it I get wrong answer, i use the same in the 498 and got Ac in that, what could be wrong with this
Code: Select all
`#include <iostream>#include <cmath>int main(){   double cof[200000], xval=0.0, r=0.0;   int x=0, a=0, k=0;   char ca=' ';   while(true)   {      x=0, r=0, a=0, k=0;      scanf("%lf%c",&xval,&ca);      while((k=scanf("%lf%c",&cof[x],&ca))>=1)      {         x++;         if(ca=='\n')            break;      }      while(a<x)      {         if(x-(a+2)>=0)         {            r+=cof[a]*(x-(a+1))*pow(xval,x-(a+2));         }         a++;      }      printf("%.0lf\n",r);      if(k!=2)         return 0;   }   return 0;}`

If you have some sample input please post it, thanks.
/********************************
********************************/

Mata
New poster

Posts: 18
Joined: Mon Dec 17, 2007 11:35 pm
Location: Queretaro

Check the cases.

Input:
Code: Select all
`11073741824 -1073741824 012147483647 -2147483647 02-1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 12-1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1-2-1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1-11 1 1`

Output:
Code: Select all
`10737418242147483647-65244729-21474836471155763769-1`

Your code prints an extra 0 at the end of output. May be your input taking part is not fully correct.
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

### stil wa

Hi, thanks for the test cases, I try them and i got the same output as you, i didn't find the extra 0 at the end of my output.
Code: Select all
`10737418242147483647-65244729-21474836471155763769-1`
/********************************
********************************/

Mata
New poster

Posts: 18
Joined: Mon Dec 17, 2007 11:35 pm
Location: Queretaro

### Re: 10268 - 498'

test cases
Code: Select all
`1000000000000001`

Code: Select all
`0`
New poster

Posts: 32
Joined: Tue Feb 13, 2007 1:31 pm

### Re: 10268 - 498'

I did something wrong?
Some one please figure my mistake. Why this gives me wa?
Code: Select all
`#include<math.h>long long int a[10000001];int main(){   long long int sum,x,i,j,t;   char c;   while(scanf("%lld",&x)==1)   {      i=0;      while(1)      {         scanf("%lld%c",&a[i++],&c);         if(c==10)break;      }      sum=0;t=0;      for(j=i-2;j>=0;j--)      {         sum += (j+1)*a[t++]*pow(x,j);      }      printf("%lld\n",sum);   }   return 0;}`
try_try_try_try_&&&_try@try.com
This may be the address of success.
Obaida
A great helper

Posts: 380
Joined: Wed Jan 16, 2008 6:51 am