CodeForces 614A(水题)

这道题有个需要注意的地方,就是范围大小

2^16 = 65535,2^32 = 65535(10^4),2^16 = 4294967295(10^9),2^64=9223372036854775807(10^18)

这道题范围到10^9,3次方就超过了long long,所以可以用除法作为判定条件

#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;

#define MEM(a,b) memset(a,b,sizeof(a))
#define pf printf
#define sf scanf
#define debug printf("!/n")
#define INF 1000
#define MAX(a,b) a>b?a:b
#define blank pf("
")
#define LL long long

int main()
{
          long long l,k,r,i;
          while(~sf("%I64d%I64d%I64d",&l,&k,&r))
          {
                    long long ans = 1;
                    bool flag = false;
                    for(;;)
                    {
                              if(ans>=l && ans<=k)
                              {
                                        flag = true;
                                        pf("%I64d ",ans);
                              }
                              if(ans>k/r)
                                        break;
                              ans*=r;
                    }
                    if(!flag)
                              pf("-1");
                    blank;

          }
          return 0;
}
原文地址:https://www.cnblogs.com/qlky/p/5154334.html