mistake in the code
Jun 10, 2014 at 8:27am UTC
i am expecting to get correct answer for every value of x, n and a[i] where
-10^9 <= a[i] <= 10^9
1 <= x <= 10^18
and 1 <= n <= 10000
every value here is an integer value
but i am wrong somewhere but dont know where
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#include<cstdio>
#include<iostream>
#include<cmath>
#include <float.h>
#define sBig long long int
using namespace std;
sBig CONS = 1000000007;
inline sBig mod(sBig a)
{ return (a%CONS+CONS)%CONS; }
sBig a[10010], rem[10010];
int n;
sBig solve(sBig x)
{
sBig temp = x;
sBig num = 0;
int s = 0;
sBig z, tmp;
bool sign;
num = 0;
num = mod(mod(x)*a[1]);
int j = 2;
for (; j <= n ; j++)
{
int nrt = floor(pow(x,1.0/(double )j));
if (nrt < 2)
break ;
tmp = mod((nrt)*a[j]);
num = mod(num + tmp);
}
sBig res = mod(num);
if (n > 1)
res = mod(num + rem[j]);
return res;
}
main()
{
int q;
sBig x;
scanf("%d%d" ,&n,&q);
rem[n+1] = 0;
sBig z;
for (int i = 1; i <= n; i++)
{
scanf("%lld" ,&a[i]);
}
for (int i = n; i > 0; i--)
rem[i] = mod(rem[i+1] + a[i]);
for (int i = 0; i < q ; i++)
{
scanf("%lld" ,&x);
printf("%lld " ,solve(x));
}
return 0;
}
Jun 11, 2014 at 12:25pm UTC
on line 45, should be
int main()
Topic archived. No new replies allowed.