結果

問題 No.1653 Squarefree
ユーザー ayaoni
提出日時 2021-08-20 22:03:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 877 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 84,928 KB
最終ジャッジ日時 2024-10-14 08:19:55
合計ジャッジ時間 25,502 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


L,R = MI()

X = [i for i in range(L,R+1)]
for i in range(2,10**6+1):
    s = i**2
    for j in range(s*((L+s-1)//s)-L,s*(R//s+1)-L,s):
        X[j] = 0
    for j in range(i*((L+i-1)//i)-L,i*(R//i+1)-L,i):
        if X[j] % i == 0:
            X[j] //= i


def is_square(x):
    y = int(x**.5)
    for i in range(y-1,y+2):
        if i**2 == x:
            return True
    return False


ans = 0
for x in X:
    if x == 1:
        ans += 1
    elif x == 0:
        continue
    else:
        if not is_square(x):
            ans += 1

print(ans)
0