MarcusV(南墙大佬的搬运工)

南墙大佬的CSDN博客地址

导航

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 on 2020-03-30 13:02  MarcusV  阅读(54)  评论(0编辑  收藏  举报