题解 | #数列#

数列

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 ???

全部评论

相关推荐

现在才开始投还有可能吗😭😭😭
牛客621925249号:开秋招了已经
点赞 评论 收藏
分享
05-09 14:45
门头沟学院 Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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