結果

問題 No.1022 Power Equation
ユーザー tamatotamato
提出日時 2020-04-10 23:16:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 921 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 81,280 KB
最終ジャッジ日時 2024-09-16 00:23:00
合計ジャッジ時間 2,254 ms
ジャッジサーバーID
(参考情報)
judge6 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    from math import log, gcd, floor
    input = sys.stdin.buffer.readline

    div = [set() for _ in range(41)]
    for i in range(1, 41):
        for j in range(2, 41):
            if i%j==0:
                div[i].add(j)

    for _ in range(int(input())):
        N = int(input())
        ans = 0
        sqrtN = int(N**0.5)
        seen = [0] * (sqrtN + 1)
        for a in range(2, sqrtN+1):
            if seen[a]:
                continue
            L = 0
            while a ** L <= N:
                L += 1
            L -= 1
            for i in range(1, L+1):
                if a**i <= sqrtN:
                    seen[a**i] = 1
                for j in range(i+1, L+1):
                    g = gcd(i, j)
                    ans += N // (j // g)
        ans *= 2
        ans += N**2 # b==d
        ans += N**2-N # a==c==1
        print(ans)


if __name__ == '__main__':
    main()
0