数列(洛谷1062)——做过,当时也是灵光一现

  之前看到的是基数仅为三的版本,只有一个输入的。我看数据范围就知道暴力出屎已成必然,而且难敲。然后我拿笔稍微划几笔,突然想到这他妈的每一个幂前边的系数都是一,不就可以把二进制一转完事吗——如下。

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4 const int N=16;
 5 int n,m,mark;
 6 long long res,pow[N]={1};
 7 bool val[N];
 8 int main(){
 9     cin>>m>>n;
10     for(int i=1;i<=10;i++)pow[i]=pow[i-1]*m;
11     
12     while(n){
13         val[mark++]=n%2;
14         n/=2;
15     }
16     for(int i=0;i<mark;i++)res+=val[i]*pow[i];
17     cout<<res<<endl;
18     return 0;
19 }
Method_01

  洛谷 Aqours 0ms

posted @ 2017-09-10 21:36  Darkins  阅读(117)  评论(0)    收藏  举报