import tkinter as tk
from tkinter import messagebox

def is_limited_factor_number(x):
    if x <= 0:
        return False
    for factor in [2, 3, 5]:
        while x % factor == 0:
            x //= factor
    return x == 1

def check_number():
    try:
        x = int(entry.get())
        if is_limited_factor_number(x):
            result_label.config(text="Yes, the number only has factors 2, 3, and 5.", fg="green")
        else:
            result_label.config(text="No, the number has other factors besides 2, 3, and 5.", fg="red")
    except ValueError:
        result_label.config(text="Please enter a valid integer.", fg="orange")

def ask_retry():
    answer = messagebox.askyesno("Try Again", "Do you want to solve another problem?")
    if answer:
        entry.delete(0, tk.END)
        result_label.config(text="", fg="black")
    else:
        root.quit()

# Initialize the main window
root = tk.Tk()
root.title("Limited Factor Number Checker")
root.geometry("450x400")

# Title label
title_label = tk.Label(root, text="Limited Factor Number Checker", font=("Arial", 16, "bold"))
title_label.pack(pady=10)

# Description label
desc_label = tk.Label(root, text="This program checks if a number is a Limited Factor Number.\n"
                                  "A Limited Factor Number contains only the factors 2, 3, and 5.", font=("Arial", 10), fg="blue")
desc_label.pack(pady=5)

# Input label and field
input_frame = tk.Frame(root)
input_frame.pack(pady=10)
input_label = tk.Label(input_frame, text="Enter a number:", font=("Arial", 12))
input_label.grid(row=0, column=0, padx=5)
entry = tk.Entry(input_frame, font=("Arial", 12), width=15)
entry.grid(row=0, column=1, padx=5)

# Check button
check_button = tk.Button(root, text="Check", command=check_number, bg="#4CAF50", fg="white", font=("Arial", 10, "bold"), width=15)
check_button.pack(pady=10)

# Result label
result_label = tk.Label(root, text="", font=("Arial", 12))
result_label.pack(pady=10)

# Retry and exit description label
retry_exit_desc = tk.Label(root, text="Select 'Try Another' to test another number, or 'Exit' to close the program.", font=("Arial", 10), fg="gray")
retry_exit_desc.pack(pady=10)

# Buttons frame for retry and exit buttons
buttons_frame = tk.Frame(root)
buttons_frame.pack(pady=10)
retry_button = tk.Button(buttons_frame, text="Try Another", command=ask_retry, bg="#FFA500", fg="white", font=("Arial", 10, "bold"), width=15)
retry_button.grid(row=0, column=0, padx=10)
exit_button = tk.Button(buttons_frame, text="Exit", command=root.quit, bg="#f44336", fg="white", font=("Arial", 10, "bold"), width=15)
exit_button.grid(row=0, column=1, padx=10)

# Start the main loop
root.mainloop()
