Created
December 22, 2015 02:03
-
-
Save peter279k/2c4897d5e460f06380b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class main{ | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
while(input.hasNext()) { | |
int x = input.nextInt(); | |
input.nextLine(); | |
String str = input.nextLine(); | |
String []str_arr = str.split(" "); | |
int number[] = new int[str_arr.length * 2]; | |
int j= 0; | |
int temp = 0; | |
temp = str_arr.length - 1; | |
for(int i=0;i<(str_arr.length*2);i+=2) { | |
number[i] = Integer.parseInt(str_arr[j]); | |
number[i+1] = temp; | |
temp -= 1; | |
j++; | |
} | |
if(number[1] == 1) { | |
System.out.println(number[0] * number[1]); | |
} | |
else { | |
for(int i=0;i<number.length;i+=2) { | |
number[i] = number[i+1] * number[i]; | |
number[i+1] -= 1; | |
} | |
int result = 0; | |
for(int i=0;i<number.length;i+=2) { | |
result += number[i] * Math.pow(x, number[i+1]); | |
} | |
System.out.println(result); | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment