QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140838#5158. Interview QuestionMohamed_Hamed#WA 24ms9036kbPython32.0kb2023-08-16 21:11:422023-08-16 21:11:43

Judging History

你现在查看的是最新测评结果

  • [2023-08-16 21:11:43]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:9036kb
  • [2023-08-16 21:11:42]
  • 提交

answer

# ﷽
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
    for i in range(a,b+1):
        if lst[i-a] =='Fizz' or lst[i-a] =='FizzBuzz':
            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':
            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)
    aa=s1.difference(s2)
    bb=s2.difference(s1)
    if aa:an=list(aa)[0]
    else:an=1
    if bb:bn=list(bb)[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: 0
Wrong Answer
time: 24ms
memory: 9036kb

input:

7 11
7 8 Fizz Buzz 11

output:

3 2

result:

FAIL Mismatch at position 8: expected 8, got Buzz