getting WA in FUNC..

enter code here
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define mod 1000000007
long long b[61];
void fill(long long x)
{
int flag=1,i=1;
while(flag)
{
if(i==1)
b[i]=x;
else
b[i]=(long long)(floor(pow(x,1.0/i)+0.0d));
if(b[i]==1)
flag=0;
i++;
}
for(;i<61;i++)
b[i]=1;
}
long *a;
int main()
{
int t,n,q,i;long long s,s1;
long long x;
scanf("%d",&t);
while(t–)
{
scanf("%d %d",&n,&q);
a=malloc(sizeof(int)*n);
for(i=0;i<n;i++)
scanf("%ld",&a[i]);
s=0;
for(i=60;i<n;i++)
s+=a[i];
while(q–)
{
i=0;
s1=0;
scanf("%lld",&x);
fill(x);
while(i<n&&i<60)
{
s1+=a[i]*b[i+1];
i++;
}
s1+=s;
s1=s1%mod;
printf("%lld ",s1);
}
}
return 0;
}
i m getting a wa… what i m doing wrong??

You can take help from the editorial.

i know dat but i m trying 2 find out what is wrong in my soln…

s1+=a[i]*b[i+1]…This will make s1 overflow at some point. a[i] can be 10^9 and also b[i+1] can be upto 10^9. You have to take mod at this intermediate point. Also you need to take care of negative values while taking mod.
For eg: -1%1000000007= 1000000006.
And still you will get TLE. Pow() function would be too slow for large values.You have to use binary search.

ok got it… thanx for your help…

//