The Golden Age

CodeForces - 813B

题目大意:如果一个数t=x^a+y^b(a,b都是大于等于0的整数)那就是一个unlucky数字。给你x,y,l,r(2 ≤ x, y ≤ 10^18, 1 ≤ l ≤ r ≤ 10^18),求出l到r内没有unlucky数字的最小区间。

解题思路:可以知道x,y最多也不会超过60次方(2^60>1e18),所以可以直接枚举x^a+y^b的值存到vector里,然后排序,找出间v[i+1]-v[i]-1(因为两端都是unlucky数字所以要两个端点都不算在长度内)最大的区间即可。要注意vector为空和两个端点的特判。还有数字的溢出问题,这个没办法直接判断是否溢出,可以通过使用一个d=r,比如每次x次方加一的时候,就将d/x,当d==0说明x^a已经超出r的范围了。

#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
// #define _ ios::sync_with_stdio(false)
// #define cin.tie(0)
using namespace std;
// #define rep(i,x,y) for(int i=x;i<y;i++)
typedef long long ll;
const int MAXN=2e5+5; vector<ll> v; int main()
{
ll x,y,l,r;
cin>>x>>y>>l>>r;
ll tx,ty;
ll d1=r;
for(int i=0;i<=61;i++)
{
if(i!=0)
d1/=x;
if(d1==0)
break;
if(i==0)
tx=1;
else
tx*=x;
ll d2=r;
for(int j=0;j<=61;j++)
{
if(j!=0)
d2/=y;
if(d2==0)
break;
if(j==0)
ty=1;
else
ty*=y;
if(tx+ty>=l&&tx+ty<=r)
v.push_back(tx+ty);
}
} if(!v.size())
{
cout<<r-l+1<<endl;
return 0;
} ll ans=0;
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
if(i==0&&v[0]!=l)
ans=max(ans,v[i]-l);
if(i==v.size()-1)
ans=max(ans,r-v[i]);
else
ans=max(ans,v[i+1]-v[i]-1);
}
cout<<ans<<endl;
return 0;
}

CodeForce-813B The Golden Age(数学+枚举)的更多相关文章

  1. Codeforces 813B The Golden Age(数学+枚举)

    题目大意:如果一个数t=x^a+y^b(a,b都是大于等于0的整数)那就是一个unlucky数字.给你x,y,l,r(2 ≤ x, y ≤ 10^18, 1 ≤ l ≤ r ≤ 10^18),求出l到 ...

  2. The Golden Age CodeForces - 813B (数学+枚举)

    Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a  ...

  3. Why The Golden Age Of Machine Learning is Just Beginning

    Why The Golden Age Of Machine Learning is Just Beginning Even though the buzz around neural networks ...

  4. 【数学】codeforces B. The Golden Age

    http://codeforces.com/contest/813/problem/B [题意] 满足n=x^a+y^b的数字为不幸运数字,a,b都是非负整数: 求闭区间[l,r]上的最长的连续幸运数 ...

  5. bzoj 1257: [CQOI2007]余数之和sum 数学 && 枚举

    1257: [CQOI2007]余数之和sum Time Limit: 5 Sec  Memory Limit: 162 MBSubmit: 1779  Solved: 823[Submit][Sta ...

  6. 2-08. 用扑克牌计算24点(25) (ZJU_PAT 数学 枚举)

    题目链接:http://pat.zju.edu.cn/contests/ds/2-08 一副扑克牌的每张牌表示一个数(J.Q.K分别表示11.12.13,两个司令都表示6).任取4张牌.即得到4个1~ ...

  7. FZU 2125 简单的等式 【数学/枚举解方程式】

    现在有一个等式如下:x^2+s(x,m)x-n=0.其中s(x,m)表示把x写成m进制时,每个位数相加的和.现在,在给定n,m的情况下,求出满足等式的最小的正整数x.如果不存在,请输出-1. Inpu ...

  8. 【数学+枚举】OpenJ_POJ - C17J Pairs

    https://vjudge.net/contest/171652#problem/J [题意] 问有多少个正整数对(x,y),使得存在正整数p,q满足 1 <= T <= 15 1 &l ...

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

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

随机推荐

  1. js引用类型深拷贝、浅拷贝方法封装

    引用类型的深拷贝.浅拷贝在前端领域一直是个很重要的知识点,不仅在业务中频繁使用,也是面试官们喜欢考的的知识点之一.本篇将封装引用类型的深拷贝.浅拷贝方法,并解决在封装过程中出现的问题. 一.浅拷贝 浅 ...

  2. Spring Cloud Alibaba - RestTemplate

    Spring Cloud Alibaba - RestTemplate Controller导入依赖和相关属性 @SuppressWarnings("all") @RestCont ...

  3. rancherUI添加configmap

    1.创建configmap 2.部署pod,挂载配置文件(通过卷的形式引用)

  4. 寻找写代码感觉(一)之使用 Spring Boot 快速搭建项目

    写在前面 现在已经是八月份了,我已经荒废了半年居多,不得不说谈恋爱确实是个麻烦的事,谈好了皆大欢喜,分手了就是萎靡不振,需要很长一段时间才能缓过来. 人还是要有梦想的,至于实现只不过是一个契机,但凡不 ...

  5. S3C2440—7.存储控制器访问外设

    文章目录 一.内存接口的概念 二.存储控制器(内存控制器) 2.1 什么是存储控制器? 2.2 S3C2440存储控制器介绍 2.3 存储控制器如何处理不同位宽的外设 2.4 怎么确定芯片的访问地址? ...

  6. 第11篇-认识Stub与StubQueue

    在 第10篇-初始化模板表 我们介绍过TemplateInterpreter::initialize()函数,在这个函数中会调用TemplateTable::initialize()函数初始化模板表, ...

  7. DOS创建/删除/描述 windows服务

    1.以管理员运行cmd ,输入 sc create test binPath= 程序路径\xxx.exe,主要 "="后面必须要空格 在服务里面查看结果 2.设置服务格式: sc ...

  8. mysql版本:'for the right syntax to use near 'identified by 'password' with grant option'

    查询mysql具体版本 SELECT @@VERSION 问题分析:mysql版本8.0.13,在给新用户授权时,发生了变化: 1064 - You have an error in your SQL ...

  9. Playwright-python 教程

    安装 pip install playwright -i https://mirrors.aliyun.com/pypi/simple/ 使用阿里源,下载速度快一点. python -m playwr ...

  10. eh-admin一套前后端一体的轻量级后台管理系统

    https://gitee.com/DawnYang/eh-admin 主要技术 后端技术:Spring Boot,Apache Shiro,MyBatis-Plus等: 前端技术:Jquery,La ...