QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#734161#7797. Based Zeroskivi_gabWA 17ms10700kbPython31.0kb2024-11-11 02:28:292024-11-11 02:28:29

Judging History

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

  • [2024-11-11 02:28:29]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:10700kb
  • [2024-11-11 02:28:29]
  • 提交

answer

import math

def count_trailing_zeros_in_base(n, base):
    count = 0
    while n % base == 0:
        n //= base
        count += 1
    return count

def find_optimal_bases(n):
    max_zeros = 0
    best_bases = []
    
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            for base in [i, n // i]:
                if base > 1: 
                    zeros = count_trailing_zeros_in_base(n, base)
                    
                    if zeros > max_zeros:
                        max_zeros = zeros
                        best_bases = [base]
                    elif zeros == max_zeros:
                        best_bases.append(base)
    
    best_bases.sort()
    return max_zeros, best_bases

results = []

for _ in range(int(input())):
    n = int(input("Enter n: "))
    max_zeros, bases = find_optimal_bases(n)
    results.append((max_zeros, len(bases), bases))

for result in results:
    max_zeros, m, bases = result
    print(max_zeros, m)
    print(" ".join(map(str, bases)))

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 17ms
memory: 10700kb

input:

3
11
1007
239

output:

Enter n: Enter n: Enter n: 1 1
11
1 3
19 53 1007
1 1
239

result:

wrong output format Expected integer, but "Enter" found