結果

問題 No.2552 Not Coprime, Not Divisor
ユーザー titiatitia
提出日時 2024-11-11 06:45:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,093 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 580 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 99,072 KB
最終ジャッジ日時 2024-11-11 06:45:43
合計ジャッジ時間 14,565 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

MAX=1000010

# 線形篩。エラトステネスの篩を線形にできる。
Sieve=[-1]*MAX
Primes=[]

for i in range(2,MAX):
    if Sieve[i]==-1:
        Primes.append(i)
        Sieve[i]=i

    for p in Primes:
        if p*i>=MAX or p>Sieve[i]:
            break
        else:
            Sieve[p*i]=p


# 素因数分解
def fact(x):
    D=dict()
    while x!=1:
        k=Sieve[x]
        if k in D:
            D[k]+=1
        else:
            D[k]=1
        x//=k
    return D


from math import gcd

N=int(input())
SP=set(Primes)

ANS=0
for x in range(4,N+1):
    LIST=list(fact(x))
    score=0

    for i in range(1<<len(LIST)):
        now=1
        count=0
        for j in range(len(LIST)):
            if i & (1<<j) != 0:
                now=now*LIST[j]
                count+=1

        if count%2==0:
            score+=N//now-x//now
        else:
            score-=N//now-x//now

    #print(x,score)

    ANS+=(N-x+1)-score-N//x

    score2=0

    #for y in range(x+1,N+1):
    #    if 1<gcd(x,y)<x:
    #        score2+=1
    #print(score2)
    #assert score2==(N-x+1)-score-N//x

print(ANS)
0