結果

問題 No.546 オンリー・ワン
ユーザー 已经死了
提出日時 2025-01-30 01:06:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 3,098 bytes
コンパイル時間 386 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 94,184 KB
最終ジャッジ日時 2025-01-30 01:06:45
合計ジャッジ時間 3,550 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

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)用a序列生成一个累积迭代器,一般list化前面放个[0]做前缀和用
#combinations(a,k)a序列选k个 组合迭代器
#permutations(a,k)a序列选k个 排列迭代器
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
#ceil向上取整,floor向下取整 ,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)]  # →↘↓↙←↖↑↗


def gcd(n1,n2):
    return gcd(n2,n1%n2) if n2>0 else n1       #最大公约数
def lcm(n1,n2):
    return n1*n2//gcd(n1,n2)                    #最小公倍数

def cal(x,y): #[1,x]中有多少个y的倍数
    if x<=0:
        return 0
    return x//y

n,l,r=li()

a=li()

#n <= 1<<60 以下くらい
def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c


res=0

def f(x,y):
    if x<=0:
        return 0
    return x//y

def cal(b,x):
    n=len(b)
    res=f(r,x)-f(l-1,x)
    for s in range(1,1<<n):
        lc=x
        for i in range(n):
            if s>>i&1:
                lc=lcm(lc,b[i])
        if popcnt(s)%2==1:
            res-=f(r,lc)-f(l-1,lc)
        else:
            res+=f(r,lc)-f(l-1,lc)
    #print(b,x,res)
    return res        
        

for i,x in enumerate(a):
    b=a[:]
    b.pop(i)
    res+=cal(b,x)

print(res)
0