P1062 数列
题目传送门
方法一:
看一下样例:
3 100
1,3,4,9,10,12,13
该序列实际上就是:
3^0 , 3^1 , 3^0 + 3^1 , 3^2 , 3^0 + 3^2 ,3^1 + 3^2 , 3^0 + 3^1 + 3^2
只看次幂:
0,1,1 0, 2, 2 0,2 1,2 1 0
再看看1~n的二进制:
1,10,11,100,101,110,111
看完后,大家应该都看到了规律。
对于一个基数为K的第i项,其实等同于:
i的二进制以k进制的形式再转回十进制。
举个例子:
来看看k=3,n=7的运算过程:
首先将7(10)转为111(2)。
然后我们按k进制转回十进制:
3^2 + 3^1 + 3^0 = 9 + 3 + 1 = 13
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
using namespace std;
const int MAX=2147483647;
const int N=1e6;
long long</