恒纪元【算法赛】

主要思路就是先求出所有的乱纪元,然后使用二分查找找到下一个恒纪元

#include <bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const int N = 1e6+7;
#define int long long 
typedef long long ll;
const int M=1e12;
int a[N];
int index1=1;
set<int>se;
int qpow(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b & 1)
            ans = ans * a ;
        a = a * a ;
        b >>= 1;
    }
    return ans ;
}
//string s;
int n,m;
int check(int s){
	int l=1,r=index1-1;
	while(l<r){
		int mid=l+r>>1;
		if(a[mid]==s)return mid;
		if(a[mid]>s)r=mid-1;
		if(a[mid]<s)l=mid+1;
	}
}
signed main()
{
  IOS; 
  int x,y,z;
  cin>>x>>y>>z;
  for(int i=0;i<=64;i++){
     for(int j=0;j<=64;j++){
for(int k=0;k<=64;k++){
         if(pow(x,i)+pow(y,j)+pow(z,k)<=M)se.insert(pow(x,i)+pow(y,j)+pow(z,k));
         else break;
  }
  }
  }

for(auto i:se){
 // cout<<i<<endl;
  a[index1++]=i;
}
  int q=0;
 cin>>q;
  while(q--){
     int s;
     cin>>s;
   int k= check(s);
   for(int t=k;;t++){
   	if(a[t]+1!=a[t+1]){
   		cout<<a[t]+1<<" "<<a[t+1]-a[t]-1<<endl;
   		break;
	   }
   }
  }
  return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值