CodeForces

来源:互联网 发布:手机淘宝有免费装修 编辑:程序博客网 时间:2024/06/10 10:46

有点坑的地方就是 结果可能超long long 要随时判断 中间值是不是会超过 给定的最大值,那样就不用算了


#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <vector>#include <set>#include <stack>#include <map>#include <climits>using namespace std;typedef unsigned long long ull;const int maxn = 100 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;ull l, r, k;int main() {    ios::sync_with_stdio(0);    cin >> l >> r >> k;    ull t = 1LL;    while(t < l) {        t *= k;        if(r / t < k) break;    }       if(t >= l && t <= r) cout << t, t *= k;    else { cout << -1 << endl; return 0;}    while(t <= r) {        cout << " " << t;        if(r/t < k) break;        t *= k;    }    return 0;}


原创粉丝点击