Y sequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 114 Accepted Submission(s): 7
Problem Description
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hates those numbers which can be written as a^b (a, b are positive integers,2<=b<=r),so he removed them all.Yellowstar calls the sequence that formed by the rest
integers“Y sequence”.When r=3,The first few items of it are:
2,3,5,6,7,10......
Given positive integers n and r,you should output Y(n)(the n-th number of Y sequence.It is obvious that Y(1)=2 whatever r is).
2,3,5,6,7,10......
Given positive integers n and r,you should output Y(n)(the n-th number of Y sequence.It is obvious that Y(1)=2 whatever r is).
Input
The first line of the input contains a single number T:the number of test cases.
Then T cases follow, each contains two positive integer n and r described above.
n<=2*10^18,2<=r<=62,T<=30000.
Then T cases follow, each contains two positive integer n and r described above.
n<=2*10^18,2<=r<=62,T<=30000.
Output
For each case,output Y(n).
Sample Input
2 10 2 10 3
Sample Output
13 14
二分答案ans,筛[2,ans]前面的a^b的数,判断去掉之后是否等于n。
TLE了。。。pow!!!
据说大表,待更新,,,
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define LL long long
long long prime[] = {2,3,5,7,11,13,17,19,23,29,
31,37,41,43,47,53,59,61,67,
71,73,79,83,89,97};
LL T,n,m;
LL input()
{
char ch;
LL tmp = 0;
while(ch=getchar(),ch!='\n'&&ch!=' '){
tmp=tmp*10+ch-'0';
}
return tmp;
}
int main()
{
// scanf("%lld",&T);
T = input();
LL h=1;
for(int i = 1;i<=62;i++)h=h*2;
while(T--)
{
// scanf("%lld%lld",&n,&m);
n=input();
m=input();
// cout<<n<<" "<<m<<endl;
LL l = 0,r=n*2;
//cout<<l<<" "<<r<<endl;
while(l<r)
{
LL mid = (l+r)/2;
LL tot = 0;
for(int i = 0;i<25;i++)
if(prime[i]<=m){
LL tmp = //pow(1.0*mid,1.0/prime[i])
exp(log(mid)/prime[i]);
tot = tot + tmp - 1;
//cout<<i<<"---"<<tmp<<endl;
}else break;
//cout<<l<<" "<<r<<" "<<mid<<" "<<tot<<endl;
if(mid - tot -1>n) r = mid-1;
else
if(mid-tot -1==n) r=mid;
else
l = mid+1;
}
printf("%lld\n",l);
}
}
本文探讨了Y序列的性质及求解方法,通过输入正整数n和r,输出Y序列中的第n个数。重点在于筛选排除特定形式的数字,保留剩余的正整数序列。
452

被折叠的 条评论
为什么被折叠?



