B. The Golden Age
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers.

For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it.

Such interval of years that there are no unlucky years in it is called The Golden Age.

You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0.

Input

The first line contains four integer numbers xyl and r (2 ≤ x, y ≤ 1018, 1 ≤ l ≤ r ≤ 1018).

Output

Print the maximum length of The Golden Age within the interval [l, r].

If all years in the interval [l, r] are unlucky then print 0.

Examples
input
  1. 2 3 1 10
output
  1. 1
input
  1. 3 5 10 22
output
  1. 8
input
  1. 2 3 3 5
output
  1. 0
Note

In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].

In the second example the longest Golden Age is the interval [15, 22].

题意:给定一个a和b 如果满足 pow(a,i)+pow(b,j),就说这个数不幸运 求一个区间内最大的没有不幸运数的区间。

思路:枚举a^i 与 b^j的值,存入vector, 计算结果

代码:

  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<string.h>
  5. #include<math.h>
  6. #include<stdlib.h>
  7. #include<ctype.h>
  8. #include<stack>
  9. #include<queue>
  10. #include<map>
  11. #include<set>
  12. #include<vector>
  13. #define ll long long
  14. #define db double
  15. using namespace std;
  16. ;
  17. ;
  18. vector<ll>a;
  19. ll x,y,l,r,ans=;
  20. int main(){
  21. scanf("%lld%lld%lld%lld",&x,&y,&l,&r);
  22. a.push_back(l-);
  23. a.push_back(r+);
  24. ;;i*=x){
  25. ;;j*=y){
  26. ll len=i+j;
  27. if(len>=l&&len<=r)a.push_back(i+j);
  28. if(j>r/y)break;//判断条件必须单写,若改为i<=r,j<=r 会MLE,因为x,y很大
  29. }
  30. if(i>r/x)break;
  31. }
  32. sort(a.begin(),a.end());
  33. ;i<a.size();i++) ans=max(ans,a[i]-a[i-]-);
  34. printf("%lld\n",ans);
  35. }

Educational Codeforces Round 22.B 暴力的更多相关文章

  1. Educational Codeforces Round 22 E. Army Creation

    Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...

  2. Educational Codeforces Round 22 B. The Golden Age(暴力)

    题目链接:http://codeforces.com/contest/813/problem/B 题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让 ...

  3. Educational Codeforces Round 21(A.暴力,B.前缀和,C.贪心)

    A. Lucky Year time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  4. Educational Codeforces Round 22 E. Army Creation 主席树 或 分块

    http://codeforces.com/contest/813/problem/E 题目大意: 给出长度为n的数组和k,  大小是1e5级别. 要求在线询问区间[l, r]权值,  权值定义为对于 ...

  5. [Educational Codeforces Round#22]

    来自FallDream的博客,未经允许,请勿转载,谢谢. 晚上去clj博客逛来逛去很开心,突然同学提醒了一下,发现cf已经开始40分钟了,慌的一B,从B题开始写,写完了B到E最后收掉了A,结果太着急B ...

  6. 【Educational Codeforces Round 22】

    又打了一场EDU,感觉这场比23难多了啊…… 艹还是我太弱了. A. 随便贪心一下. #include<bits/stdc++.h> using namespace std; ,ans=- ...

  7. Educational Codeforces Round 22 E. Army Creation(分块好题)

    E. Army Creation time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. Educational Codeforces Round 22 补题 CF 813 A-F

    A The Contest 直接粗暴贪心 略过 #include<bits/stdc++.h> using namespace std; int main() {//freopen(&qu ...

  9. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

随机推荐

  1. 分辨率、像素和PPI

    屏幕尺寸是指屏幕对角线的长度,一般以英寸为单位,1英寸(inch)=2.54厘米(cm).传统意义上的照片尺寸也是这个概念.所以同样尺寸(指对角线)的屏幕,也可能长宽比率不同.像素(Pixel):是位 ...

  2. 解决Cornerstone不能上传.a文件的问题 Cornerstone不上传*.xcuserstate,*.xcbkptlist文件

    在使用CornerStone的时候经常会出现.a文件无法上传的问题,导致从svn checkout到本地的时候编译报错 这里可以通过配置CornerStone来达到上传.a文件的效果 操作步骤: 打开 ...

  3. .Net程序员学用Oracle系列(30):零碎补充、最后总结(The End)

    1.同义词 2.Flashback 技术 3.连接字符串的写法 4.转义字符 & 特殊运算符 5.文件类型 6.查看参数 & 修改参数 7.AWR 工具 8.学习方法 & 学习 ...

  4. 在Eclipse IDE使用Gradle构建应用程序

    文 by / 林本托 Tips 做一个终身学习的人. 1. 下载和配置Gradle Gradle Inc.是Gradle框架开发的公司,为Eclipse IDE提供了Gradle工具的支持. 此工具可 ...

  5. 详解Linux进程(作业)的查看和杀死

    目录: 引入进程 进程 线程 PS命令 TOP命令 其他查看进程命令 进程的优先级 作业控制机制 kill命令 一.引入进程 1.内存划分为:用户空间和内核空间 1.在用户空间里运行的进程,就是用户进 ...

  6. python 字符串常用方法

    字符串常用方法 capitalize() String.capitalize() 将字符串首字母变为大写 name = 'xiaoming' new_name = name.capitalize() ...

  7. C#码农的大数据之路 - 使用C#编写MR作业

    系列目录 写在前面 从Hadoop出现至今,大数据几乎就是Java平台专属一般.虽然Hadoop或Spark也提供了接口可以与其他语言一起使用,但作为基于JVM运行的框架,Java系语言有着天生优势. ...

  8. js 玩一玩

    闲着没事学了学js,做了一个下页面玩玩. 下面是html代码: <!DOCTYPE html><html> <head> <meta charset=&quo ...

  9. 禁止右键,禁止选中,禁止网页复制的Js代码

    document.oncontextmenu=new Function('event.returnValue=false;'); document.onselectstart=new Function ...

  10. Android网络请求框架AsyncHttpClient实例详解(配合JSON解析调用接口)

    最近做项目要求使用到网络,想来想去选择了AsyncHttpClient框架开进行APP开发.在这里把我工作期间遇到的问题以及对AsyncHttpClient的使用经验做出相应总结,希望能对您的学习有所 ...