Java实现洛谷 P1062 数列
P1062 数列
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
int n = sc.nextInt();
sc.close();
ArrayList<Integer> list = new ArrayList<Integer>();
while(n!=0){
list.add(n%2);
n/=2;
}
long sum=0l;
for (int i = 0; i < list.size(); i++)
{
sum = (long) (sum + list.get(i) * Math.pow(num, i));
}
System.out.println(sum);
}
}