QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140852 | #5158. Interview Question | Mohamed_Hamed# | WA | 32ms | 9068kb | Python3 | 2.3kb | 2023-08-16 21:23:13 | 2023-08-16 21:23:14 |
Judging History
answer
# ﷽
from itertools import accumulate
from math import gcd
import sys
input = lambda: sys.stdin.readline().strip()
def inlst():return [int(i) for i in input().split()]
class PrimeFactorisation:
def __init__(self, mx):
self.mx = mx
self.primes = []
self.factor = [-1] * (mx + 1)
for i in range(2, mx + 1):
if self.factor[i] == -1:
self.primes += [i]
for j in range(i, mx + 1, i):
self.factor[j] = i
def factorise(self, n):
"""Returns a list of tuples (prime, exponent) representing the prime factorisation of n."""
prime_factorisation = []
while n > 1:
prime, exp = self.factor[n], 0
while n % prime == 0:
exp += 1
n //= prime
prime_factorisation += [(prime, exp)]
return prime_factorisation
def divisors(self,n):
"""returns a list of all distinct factors of n"""
factors = [1]
for p, exp in self.factorise(n):
factors += [p**i * factor for factor in factors for i in range(1, exp + 1)]
return factors
pf=PrimeFactorisation(1+10**5)
def solve():
a,b=inlst()
lst=input().split()
# s1=set()
# s2=set()
# u,v=0,0
d1=[]
d2=[]
for i in range(a,b+1):
if lst[i-a] =='Fizz' or lst[i-a] =='FizzBuzz':d1.append(i)
# tmp=set()
# for h,k in pf.factorise(i):tmp.add(h)
# if u==0:s1=tmp.copy();u=1
# else:s1=s1.intersection(tmp)
if lst[i-a]=='Buzz' or lst[i-a] =='FizzBuzz':d2.append(i)
# tmp=set()
# for h,k in pf.factorise(i):tmp.add(h)
# if v==0:s2=tmp.copy();v=1
# else:s2=s2.intersection(tmp)
if d1:aa=list(accumulate(d1,gcd))[-1]
else:aa=1
if d2:bb=list(accumulate(d2,gcd))[-1]
else:bb=1
print(aa,bb)
# # aa=s1.difference(s2)
# # bb=s2.difference(s1)
# print(s1,s2)
# if s1:an=list(s1)[0]
# else:an=1
# if s2:bn=list(s2)[0]
# else:bn=1
# if an==1 and bn==1:
# an=3
# bn=5
# # print(b)
# # print(aa,bb)
# # print(s1,s2)
# print(an,bn)
if __name__ == "__main__":
# for i in range(int(input())):
solve()
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 28ms
memory: 8952kb
input:
7 11 7 8 Fizz Buzz 11
output:
9 10
result:
ok
Test #2:
score: 0
Accepted
time: 32ms
memory: 8960kb
input:
49999 50002 49999 FizzBuzz 50001 Fizz
output:
2 50000
result:
ok
Test #3:
score: 0
Accepted
time: 20ms
memory: 8980kb
input:
8 11 Buzz Buzz FizzBuzz Buzz
output:
10 1
result:
ok
Test #4:
score: -100
Wrong Answer
time: 23ms
memory: 9068kb
input:
10 15 10 11 12 13 14 15
output:
1 1
result:
FAIL Mismatch at position 10: expected 10, got FizzBuzz