Consider the palindromic prime numbers(Numbers which are palindrome as well as…
- User
Consider the palindromic prime numbers(Numbers which are palindrome as well as prime).Let p be the product of non zero digits of a nth palindromic prime number.Let product of digits of a palindromic prime is multiplied by a number m to generate number q(q=p*m).Your task is simple; you have to find number of divisors of q. INPUT:
First Line contains number of test cases t. Second line contains two space separated numbers n and m.
OUTPUT:
Output each test case in new line number of divisors of q.
CONSTRAINTS:
t ≤ 10000 n ≤ 113 1 ≤ m ≤ 100
SAMPLE INPUT 1 2 1
SAMPLE OUTPUT 2
Explanation
2nd palindromic prime is 3 value of m is 1 so value of q is 3.Numbers of divisors of 3 is 2(1 and 3)
Assistant
pythondef is_prime(n): if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True pal_primes = [] current = 2 while len(pal_primes) < 113: s = str(current) if s == s[::-1] and is_prime(current): pal_primes.append(current) current += 1 def get_p(prime): product = 1 for d in str(prime): if d != '0': product *= int(d) return product def count_divisors(q): if q == 0: return 0 temp = q divisors_count = 1 exponent_2 = 0 while temp % 2 == 0: exponent_2 += 1 temp //= 2 if exponent_2 > 0: divisors_count *= (exponent_2 + 1) i = 3 while i * i <= temp: exponent = 0 while temp % i == 0: exponent += 1 temp //= i if exponent > 0: divisors_count *= (exponent + 1) i += 2 if temp > 1: divisors_count *= 2 return divisors_count t = int(input()) for _ in range(t): n, m = map(int, input().split()) prime = pal_primes[n-1] p = get_p(prime) q = p * m print(count_divisors(q))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.