Educational Codeforces Round 22-B. The Golden Age-暴力枚举+map

33 篇文章 0 订阅
6 篇文章 0 订阅

http://codeforces.com/contest/813/problem/B
给定一个a和b
如果满足 pow(a,i)+pow(b,j),就说这个数不幸运
求一个区间内最大的没有不幸运数的区间。
数据范围
Input
The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 1018, 1 ≤ l ≤ r ≤ 1018).
方法:暴力枚举,
用map存数,方便计算区间。
map count用来判断是否有没有这个数
用find来判断这个数的位置

#include<bits/stdc++.h>
using namespace std;
/*这道题好暴力。
首先要知道longlong64位,所以65就能存下。
然后暴力用map来存一下位数。
66的。

*/
typedef long long int ll;
const ll N=1e18+1;
ll x[100],y[100];
map<ll,ll>s;
int main()
{//freopen("t.txt","r",stdin);
   ll a,b,l,r;
   cin>>a>>b>>l>>r;
    memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
    x[0]=1;
    y[0]=1;
    //cout<<l<<endl;
    //cout<<r<<endl;
      s[l-1]=1;
       s[r+1]=1;
   //x[1]=a;
   //y[1]=b;
   for(int i=1;x[i-1]<=N/a;i++)
       x[i]=x[i-1]*a;
   for(int j=1;y[j-1]<=N/b;j++)
         y[j]=y[j-1]*b;
   for(int i=0;x[i]!=0;i++)
      for(int j=0;y[j]!=0;j++)
          if(x[i]+y[j]<=r&&s.count(x[i]+y[j])==0&&x[i]+y[j]>=l)
             s[x[i]+y[j]]=1;
       map<ll,ll>::iterator fir,sec;
       sec=s.begin();
       fir=s.begin();
       sec++;
       ll ans=0;
       //for(fir;fir!=s.end();fir++)
          //cout<<fir->first<<endl;
       for(;sec!=s.end();sec++,fir++)
       {   ans=max(ans,sec->first-fir->first-1);


       }
       cout<<ans<<endl;



 return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值