Link/Cut Tree CodeForces - 614A

拿到这道题一看,题意很简单,要你输出l,r里 k的power次,不存在的话输出-1;一开始简单的看了一下数据范围,感觉没什么问题。 后来发现,数据大一点的话很有可能就会溢出,那么再加个判断就可以解决溢出的问题。

/***If I get TLE , it is good.If I get AC,it's NICE !***/
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
#include <sstream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int INF=2147483647;
const int MAXN=1e5+10;
const ll mod=1e9+7;
using namespace std;
typedef long long ll;
int main(void)
{
    ll l, r,k;
    cin >> l >>r >>k;
    if(k>r && l==1)
    {
        printf("1\n");
        return 0;
    }
    ll x=1;
    int flag=0;
    while(x<=r)
    {
        if(x>=l && x<=r)
            {flag=1;break;}
         x*=k;
        if(x%k!=0)
            break;
    }
    if(flag==0)
    {
        printf("-1\n");
        return 0;
    }
    ll ans=1;
    int cnt=1;
    while(ans<=r)
    {
        if(ans>=l && ans<=r)
        {
            if(cnt==1)
            {
                printf("%I64d",ans);
                cnt=2;
            }
            else
                printf(" %I64d",ans);
        }
        ll t=ans;
        ans=ans*k;
        if(ans % t!=0)  break;
        if(ans%k!=0)
            break;
    }
    puts("");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值