Pages

3/14/2014

UVA 927 - Integer Sequence solution

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tc = sc.nextInt();

while(tc-- >0) {
int [] num = new int[sc.nextInt()+1];
int ctr=0;
for(int i=0;i<num.length;i++) {

num[i] = sc.nextInt();
}
int d =sc.nextInt();
int k= sc.nextInt();
long v=0,c=0;

for(int i =0;c<=k;i++) {
c=c+ i * d;
v=0;
for(int l=0;l<num.length;l++ ) {

   v = (long) (v +  (long)num[l]* Math.pow(i,l));
}
if (c>=k){
System.out.println(v);
break;
}
}
}
}

}

No comments :

Post a Comment