import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
String m="";
while ((m=br.readLine())!=null) {
StringTokenizer st=new StringTokenizer(m);
int []arr=new int[st.countTokens()];
for(int i=arr.length-1;i>-1;i--){
arr[i]=Integer.parseInt(st.nextToken());
}
st=new StringTokenizer(br.readLine());
int val;
int counterTok=st.countTokens();
for(int i=0;i<counterTok;i++){
if(i>0)
sb.append(" ");
val=Integer.parseInt(st.nextToken());
long sum=arr[0];
long temp=1;
for(int j=1;j<arr.length;j++){
temp*=val;
sum+=arr[j]*temp;
}
sb.append(sum);
}
sb.append("\n");
}
System.out.print(sb);
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer("");
String m="";
while ((m=br.readLine())!=null) {
StringTokenizer st=new StringTokenizer(m);
int []arr=new int[st.countTokens()];
for(int i=arr.length-1;i>-1;i--){
arr[i]=Integer.parseInt(st.nextToken());
}
st=new StringTokenizer(br.readLine());
int val;
int counterTok=st.countTokens();
for(int i=0;i<counterTok;i++){
if(i>0)
sb.append(" ");
val=Integer.parseInt(st.nextToken());
long sum=arr[0];
long temp=1;
for(int j=1;j<arr.length;j++){
temp*=val;
sum+=arr[j]*temp;
}
sb.append(sum);
}
sb.append("\n");
}
System.out.print(sb);
}
}
No comments:
Post a Comment