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);
}
}

posted @ 2020-03-30 13:02  南墙1  阅读(60)  评论(0编辑  收藏  举报