View Code of Problem 3571

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

Double click to view unformatted code.


Back to problem 3571