結果

問題 No.2829 GCD Divination
ユーザー 已经死了
提出日時 2025-03-23 23:49:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 5,380 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,840 KB
実行使用メモリ 418,144 KB
最終ジャッジ日時 2025-03-23 23:50:12
合計ジャッジ時間 20,717 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 4 WA * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import os,sys,random,threading
#sys.exit() 退
#sys.setrecursionlimit(10**6) #
from random import randint,choice,shuffle
#randint(a,b)[a,b]
#choice(seq)seq,,seq
#shuffle(x)x
from copy import deepcopy
from io import BytesIO,IOBase
from types import GeneratorType
from functools import lru_cache,reduce
#reduce(op,)
from bisect import bisect_left,bisect_right
#bisect_left(x) x
#bisect_right(x) x
from collections import Counter,defaultdict,deque
from itertools import accumulate,combinations,permutations
#accumulate(a)alist[0]
#combinations(a,k)ak
#permutations(a,k)ak
from heapq import heapify,heappop,heappush
#heapify
from typing import Generic,Iterable,Iterator,TypeVar,Union,List
from string import ascii_lowercase,ascii_uppercase,digits
#
from math import ceil,floor,sqrt,pi,factorial,gcd,log,log10,log2,inf
#ceilfloor sqrt factorial
from decimal import Decimal,getcontext
#Decimal(s) Decimal,使
#getcontext().prec=100
from sys import stdin, stdout, setrecursionlimit
input = lambda: sys.stdin.readline().rstrip("\r\n")
MI = lambda :map(int,input().split())
li = lambda :list(MI())
ii = lambda :int(input())
mod = int(1e9 + 7) #998244353
inf = 1<<60
py = lambda :print("YES")
pn = lambda :print("NO")
DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] #
DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),(-1, 1)] # →↘↓↙←↖↑↗
class PrimeTable:
def __init__(self, n=int((10**9)**0.5)+3) -> None:
#1e9(10**9)**0.5
#nn
self.n = n
self.primes = [] #n
self.min_div = [0] * (n+1)
self.min_div[1] = 1
mu = [0] * (n+1)
phi = [0] * (n+1)
mu[1] = 1
phi[1] = 1
self.mu=mu
for i in range(2, n+1):
if not self.min_div[i]:
self.primes.append(i)
self.min_div[i] = i
mu[i] = -1
phi[i] = i-1
for p in self.primes:
if i * p > n: break
self.min_div[i*p] = p
if i % p == 0:
phi[i*p] = phi[i] * p
break
else:
mu[i*p] = -mu[i]
phi[i*p] = phi[i] * (p - 1)
# x
def is_prime(self, x:int):
if x < 2: return False
if x <= self.n: return self.min_div[x] == x
for p in self.primes:
if p * p > x: break
if x % p == 0: return False
return True
# x:[p, cnt] pcnt
# yield
#
#n = x^a * y^b * z^c ... x,y,z n=(a+1)(b+1)...(y+1)
def prime_factorization(self, x:int):
for p in self.primes:
if p * p > x: break
if x <= self.n: break
if x % p == 0:
cnt = 0
while x % p == 0: cnt += 1; x //= p
yield p, cnt
while (1 < x and x <= self.n):
p, cnt = self.min_div[x], 0
while x % p == 0: cnt += 1; x //= p
yield p, cnt
if x >= self.n and x > 1:
#(10**9)**0.51
# n
yield x, 1
# x
def get_factors(self, x:int):
factors = [1]
for p, b in self.prime_factorization(x):
n = len(factors)
for j in range(1, b+1):
for d in factors[:n]:
factors.append(d * (p ** j))
return factors
def isprime(n): #
if n<2:
return False
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
def tag_primes_eratosthenes(n):
# ,[0,n)
# 1e51299709
# 1e59592
primes = [ True ]*n
primes[ 0 ] = primes[ 1 ] = False # 01
for i in range(2,int(n**0.5)+1):
if primes[i]:
primes[i * i::i] = [ False ] * ((n - 1 - i * i) // i + 1)
return primes
n=ii()
pt = PrimeTable(n+1)
dp=[0]*(n+1)
def cal(x):
fac=sorted(pt.get_factors(x))
m=len(fac)
cnt=[0]*m
for i in range(m-1,-1,-1):
cnt[i]=x//fac[i]
for j in range(i+1,m):
if fac[j]%fac[i]==0:
cnt[i]-=cnt[j]
ans=1
for j in range(m-1):
ans+=cnt[j]*dp[fac[j]]
dp[x]=ans/(1-1/x)
for i in sorted(pt.get_factors(n)):
if i==1:
continue
cal(i)
print(dp[-1])
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0