2015 Multi-University Training Contest 1 Hdu 5297 Y sequence

本文探讨了Y序列的性质及求解方法,通过输入正整数n和r,输出Y序列中的第n个数。重点在于筛选排除特定形式的数字,保留剩余的正整数序列。

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).
 

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.
 

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);
    }
}




评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值