sicily1344数列

还有一种把n转化成二进制数的方法,在这里我就不写出来了。

// Problem#: 1344
// Submission#: 1230546
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include<iostream>
#include<cmath>
using namespace std;
int a[1005];
int main()
{
    int num,k;
    while(cin>>num>>k)
    {
        int n=0,m=0,w=0;
        //memset(a,0,sizeof(a));
        while(m!=k)
        {
            a[++m]=(int)pow((double)num,n++);
            if(m==k)  break;
            w=m;
            for(int i=1;i<w;i++){
                a[++m]=a[w]+a[i];
                if(m==k) break;
            }
        }
        cout<<a[k]<<endl;
    }
    return 0;
}                                

你可能感兴趣的:(sun)