結果

問題 No.1666 累乗数
ユーザー merlinmerlin
提出日時 2021-09-03 23:15:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,608 ms / 2,000 ms
コード長 1,904 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 80,048 KB
実行使用メモリ 53,008 KB
最終ジャッジ日時 2023-08-22 01:01:08
合計ジャッジ時間 29,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
51,868 KB
testcase_01 AC 1,037 ms
52,796 KB
testcase_02 AC 1,070 ms
52,788 KB
testcase_03 AC 1,083 ms
52,536 KB
testcase_04 AC 1,091 ms
52,496 KB
testcase_05 AC 1,608 ms
52,844 KB
testcase_06 AC 1,604 ms
52,784 KB
testcase_07 AC 1,594 ms
52,696 KB
testcase_08 AC 1,591 ms
52,708 KB
testcase_09 AC 1,212 ms
52,444 KB
testcase_10 AC 1,239 ms
52,672 KB
testcase_11 AC 1,245 ms
52,772 KB
testcase_12 AC 1,253 ms
52,428 KB
testcase_13 AC 1,534 ms
52,692 KB
testcase_14 AC 1,535 ms
52,460 KB
testcase_15 AC 1,538 ms
52,764 KB
testcase_16 AC 1,535 ms
52,428 KB
testcase_17 AC 1,360 ms
52,752 KB
testcase_18 AC 1,424 ms
53,008 KB
testcase_19 AC 1,346 ms
52,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int t=Integer.parseInt(bu.readLine());
        while(t-->0)
        {
            int n=Integer.parseInt(bu.readLine());
            long l=1,r=(long)1e18,mid,ans=r;
            while(l<=r)
            {
                mid=(l+r)>>1;
                if(count(mid)>=n)
                {
                    ans=mid;
                    r=mid-1;
                }
                else l=mid+1;
            }
            sb.append(ans+"\n");
        }
        System.out.print(sb);
    }

    static long c[]=new long[61];
    static int ex[]={0,0,1000000001,1000001,31623,3982,1001,373,178,101,64,44,32,25,20,16,14,12,11,9,8,8,7,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2};
    static long count(long n)
    {
        int i,N=60;
        for(i=2;i<=N;i++)
        {
            int l=2,r=ex[i],mid,ans=0; long v;
            while(l<=r)
            {
                mid=(l+r)>>1;
                v=power(mid,i,n);
                if(v<=n)
                {
                    ans=mid-1;
                    l=mid+1;
                }
                else r=mid-1;
            }
            c[i]=ans;
        }

        int j; long ans=1;
        for(i=N;i>1;i--)
        {
            //System.out.print(c[i]+" ");
            for(j=2*i;j<=N;j+=i) c[i]-=c[j];
            ans+=c[i];
        }
        //System.out.println(n+" "+ans);
        return ans;
    }

    static long power(long a,int b,long n)
    {
        if(a>n) return n+1;
        long res=1;
        while(b!=0)
        {
            if(res>n/a) return n+1;
            res=res*a;
            b--;
            if(res>n) return n+1;
        }
        return res;
    }
}
0