একটি বড় পজিটিভ ইন্টিজার N দেওয়া আছে। এর ডিজিট পারমুটেশন থেকে কি এমন কোনো সংখ্যা পাওয়া যায় যা প্যালিনড্রোম এবং ৩ দিয়ে বিভাজ্য।
উদাহরণ
ইনপুট: input_num = 132213
আউটপুট: One or more permutation is a palindrome and is divisible by three
ব্যাখ্যা: ১২৩৩২১ প্যালিনড্রোম এবং ৩ দিয়ে বিভাজ্য।
শর্ত
- সর্বমোট ডিজিট সম ৩ দিয়ে বিভাজ্য হতে হবে (তবে সব পারমুটেশনের জন্য একই)।
- প্যালিনড্রোম বানাতে হলে 많아 गये যোদ্দি একটা ক্যারেক্টারের ফ্রিকোয়েন্সি বিজোড় হতে পারে।
উদাহরণ কোড
def solve(input_num):
digit_array = [0] * 10
input_sum = 0
while input_num:
input_sum += input_num % 10
digit_array[input_num % 10] += 1
input_num //= 10
if input_sum % 3 != 0:
return False
index_odd = 0
for i in range(10):
if digit_array[i] % 2 != 0:
index_odd += 1
if index_odd > 1:
return "No permutation is a palindrome and is divisible by three"
else:
return "One or more permutation is a palindrome and is divisible by three"
input_num = 132213
print(solve(input_num))
ইনপুট
132213
আউটপুট
One or more permutation is a palindrome and is divisible by three