题解 | #数列#

数列

https://ac.nowcoder.com/acm/problem/16668

没注意到进制,自己想的一种野方法,凑合着看吧
#include <bits/stdc++.h>
using namespace std;
#define int long long 
signed main(){
    cin.tie(0) -> ios::sync_with_stdio(0);
    int n,k;cin >> k >> n;
    vector<int> ans(n+5);
    int now = 0,total = 1,total_pre = 0, now_up = 0;
    while (total <= n){
        for (int i = 0; i < total_pre + 1;i++) {
            ans[total] = ans[now] + (int)pow(k,now_up);
            now++;
            if (total == n){
                cout << ans[total];
                return 0;
            }
            total++;
        }
        now = 0;
        total_pre+=total_pre+1;
        now_up++;
    }
//     for (int i = 0;i <= n;i++)cout << ans[i] << ' ' ;
    cout << ans[n];
    return 0;
}

PS: 2.1E9 为啥要long long ???

全部评论

相关推荐

点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务