Educational Codeforces Round 22.B 暴力
1 second
256 megabytes
standard input
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.
The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 1018, 1 ≤ l ≤ r ≤ 1018).
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.
2 3 1 10
1
3 5 10 22
8
2 3 3 5
0
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, 计算结果
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define db double
using namespace std;
;
;
vector<ll>a;
ll x,y,l,r,ans=;
int main(){
scanf("%lld%lld%lld%lld",&x,&y,&l,&r);
a.push_back(l-);
a.push_back(r+);
;;i*=x){
;;j*=y){
ll len=i+j;
if(len>=l&&len<=r)a.push_back(i+j);
if(j>r/y)break;//判断条件必须单写,若改为i<=r,j<=r 会MLE,因为x,y很大
}
if(i>r/x)break;
}
sort(a.begin(),a.end());
;i<a.size();i++) ans=max(ans,a[i]-a[i-]-);
printf("%lld\n",ans);
}
Educational Codeforces Round 22.B 暴力的更多相关文章
- Educational Codeforces Round 22 E. Army Creation
Educational Codeforces Round 22 E. Army Creation 题意:求区间[L,R]内数字次数不超过k次的这些数字的数量的和 思路:和求区间内不同数字的数量类似,由 ...
- Educational Codeforces Round 22 B. The Golden Age(暴力)
题目链接:http://codeforces.com/contest/813/problem/B 题意:就是有一个数叫做不幸运数,满足题目的 n = x^a + y^b,现在给你一个区间[l,r],让 ...
- 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 ...
- Educational Codeforces Round 22 E. Army Creation 主席树 或 分块
http://codeforces.com/contest/813/problem/E 题目大意: 给出长度为n的数组和k, 大小是1e5级别. 要求在线询问区间[l, r]权值, 权值定义为对于 ...
- [Educational Codeforces Round#22]
来自FallDream的博客,未经允许,请勿转载,谢谢. 晚上去clj博客逛来逛去很开心,突然同学提醒了一下,发现cf已经开始40分钟了,慌的一B,从B题开始写,写完了B到E最后收掉了A,结果太着急B ...
- 【Educational Codeforces Round 22】
又打了一场EDU,感觉这场比23难多了啊…… 艹还是我太弱了. A. 随便贪心一下. #include<bits/stdc++.h> using namespace std; ,ans=- ...
- 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 ...
- Educational Codeforces Round 22 补题 CF 813 A-F
A The Contest 直接粗暴贪心 略过 #include<bits/stdc++.h> using namespace std; int main() {//freopen(&qu ...
- Educational Codeforces Round 37
Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...
随机推荐
- application 从web.xml中获取初始化参数
<span style="font-size:24px;"> </span> 1.web.xml中的配置部分 <context-param> ...
- Android官方架构组件介绍之LifeCycle
Google 2017 I/O开发者大会于近日召开,在开发者大会上谷歌除了发布了Android O等一些新产品之外,也对Android代码的架构做出了一个官方的回应. Google 2017 I/O开 ...
- Circuit Breaker Features
Better to use a circuit breaker which supports the following set of features: Automatically time-out ...
- java 操作 redis
1.Java 使用 Redis 只需要下载一个jar包即可 地址:http://maven.outofmemory.cn/redis.clients/jedis/2.5.2/ 工程
- php原生自定义验证码,5分钟搞定你的问题
当然现在很多php的框架里面自带了很多很多验证码,我的这个验证码,也是当初刚刚入行的时候学习模仿的.现在照搬出来,希望对刚入门的朋友有所帮助. **************************** ...
- [asp.net mvc 奇淫巧技] 04 - 你真的会用Action的模型绑定吗?
在QQ群或者一些程序的交流平台,经常会有人问:我怎么传一个数组在Action中接收.我传的数组为什么Action的model中接收不到.或者我在ajax的data中设置了一些数组,为什么后台还是接收不 ...
- 7.ReadWriteLock接口及其实现ReentrantReadWriteLock
Java并发包的locks包里的锁基本上已经介绍得差不多了,ReentrantLock重入锁是个关键,在清楚的了解了同步器AQS的运行机制后,实际上再分析这些锁就会显得容易得多,这章节主讲另外一个重要 ...
- 【小练习06】HTML+CSS--电影公告
要求实现如下效果图: 代码演示 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- 对 dotweb 框架进行统一的自定义错误处理
助移动端的增长,如今 RESTful 风格的 API 已经十分流行, 用各种语言去写后端 API 都有很成熟方便的方案,用 golang 写后端 API 更是生产力的代表, 你可以用不输 python ...
- 导入java项目时出现红色叹号问题的解决
问题:导入java项目时出现红色叹号(如下图所示) 原因:引入项目的某些jar包跟自己电脑上的位置不一样: 解决方案:步骤如下 (1)右键红色叹号所在项目————>build path————& ...