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_palindrome(n): s = str(n) return s == s[::-1] def is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False sqrt_n = int(n**0.5) + 1 for i in range(3, sqrt_n, 2): if n % i == 0: return False return True palindromic_primes = [] current = 2 while len(palindromic_primes) < 113: if is_palindrome(current) and is_prime(current): palindromic_primes.append(current) current += 1 def count_divisors(q): if q == 0: return 0 if q == 1: return 1 factors = {} temp = q while temp % 2 == 0: factors[2] = factors.get(2, 0) + 1 temp //= 2 i = 3 max_factor = int(temp**0.5) + 1 while i <= max_factor and temp > 1: while temp % i == 0: factors[i] = factors.get(i, 0) + 1 temp //= i max_factor = int(temp**0.5) + 1 i += 2 if temp > 1: factors[temp] = 1 res = 1 for e in factors.values(): res *= (e + 1) return res t = int(input()) for _ in range(t): n, m = map(int, input().split()) prime = palindromic_primes[n-1] p = 1 for d in str(prime): if d != '0': p *= int(d) 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.