ZOJ 3665 Yukari's Birthday (2012长春现场赛K题)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define LL long long
LL X = 1000000000000ll;
struct nod{
    int r,k;
} re[12000];
int cnt;
LL oor0(int r,int k)
{
    LL ret=0;
    for(int i=1;i<=r;i++)
    {
        ret+=pow(k,i);
        if(ret>X) return -1;
    }
    return ret;
}
map<LL,int> mp;

void init()
{
    for(int i=3;i<64;i++)
    {
        for(int j=2;j<10009;j++)
        {
            LL t = oor0(i,j);
            if(t<=0) break;
            re[cnt].r = i,re[cnt].k = j;
            mp[t] = cnt;
            cnt++;
            t++;
        }
    }
}
int main()
{
    freopen("in.txt","r",stdin);
    init();
    LL a;
    LL x,y;
    while(cin>>a)
    {
        if(mp.find(a)!=mp.end())
        {
            int k = mp[a];
            x = re[k].r,y=re[k].k;
        } else if(mp.find(a-1)!=mp.end())
        {
            int k = mp[a-1];
            x = re[k].r,y=re[k].k;
        }else{
            LL k = (LL)sqrt(a);//cout<<k<<endl;
            if(k*(k+1)==a||k*(k+1)==a-1){
                x = 2,y =k;
            }else{
                x = 1,y=a-1;
            }
        }
        cout<<x<<" "<<y<<endl;
    }
    return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值