标签:
2 10 2 10 3
13 14
/* ***********************************************
Author :CKboss
Created Time :2015年08月09日 星期日 15时03分31秒
File Name :HDOJ5297.cpp
************************************************ */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int LL;
LL ss[19]={0, -2, -3, -5, -7, -11, -13, -17, -19, -23, -29, -31, -37, -41, -43, -47, -53, -59, -61};
vector<LL> a;
LL n,r;
LL gao(LL x)
{
LL ret=x;
for(int i=0,sz=a.size();i<sz;i++)
{
LL cnt=(LL)pow(x+0.5,1.0/abs(a[i]))-1;
if(a[i]<0) ret-=cnt;
else ret+=cnt;
}
return ret-1;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T_T;
cin>>T_T;
while(T_T--)
{
cin>>n>>r;
a.clear();
for(int i=1;i<=18&&abs(ss[i])<=r;i++)
{
int k=a.size();
for(int j=0;j<k;j++)
{
if(abs(a[j]*ss[i])>63) continue;
LL t=a[j]*ss[i];
a.push_back(t);
}
a.push_back(ss[i]);
}
LL ans=n;
while(true)
{
LL left=gao(ans);
if(left==n) break;
ans=ans+n-left;
}
cout<<ans<<endl;
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/ck_boss/article/details/47377959