输入包括t+1行,第一行包括一个整数t(1 ≤ t ≤ 10), 接下来t行,每行一个整数x(1 ≤ x ≤ 10^6)
对于每个x,如果可能重排之后变为自己的倍数输出"Possible", 否则输出"Impossible".
2 14 1035
Impossible Possible
import itertools def process(num): all_permutations = itertools.permutations(str(num)) for each in all_permutations: change = int(''.join(each)) if change != num and change > num: if change % num == 0: print("Possible") return print("Impossible") if __name__ == "__main__": t = int(input()) for i in range(t): process(int(input()))