#P1326. Intersection Set of Prime Factors

    ID: 327 传统题 400ms 64MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>普及/提高-筛法暴力枚举深度优先搜索数论数学双指针

Intersection Set of Prime Factors

Intersection Set of Prime Factors

题目描述

Given a positive integer nn. Select two distinct digits from the decimal repersentation(十进制表示)of nn, we obtain another integer mm. What is the size of the intersection set(交集)of the prime factors of nn and mm? For example, given n=623457198n=623457198, its prime factor set is A={2,3,7,13,380621}A = \{2, 3, 7, 13, 380621\}. Swapping 22 and 99 gives us m=693457128m=693457128, of which the prime factor set is B={2,3,7,13,109,971}B = \{2, 3, 7, 13, 109, 971\}. Then the intersection set of AA and BB is {2,3,7,13}\{2, 3, 7, 13\}, with 44 factors.

输入格式

Each input file contains one test case, which gives a positive integer nn (10<n109)(10<n≤10^9). It is guaranteed that there are at least 22 distinct digits in nn.

输出格式

Swap any pair of digits in nn to obtain mm, you are supposed to find the mm with the largest intersection set of the prime factors of nn and mm. Output in a line the number of the prime factors in the intersection set, together with mm. The numbers must be separated by 11 space, and there must be no extra space at the beginning or the end of the line. In case such an mm is not unique, output the one with the smallest value.

样例 #1

样例输入 #1

623457198

样例输出 #1

4 123457698

提示

There are two msm's with 44 common factors. Besides the one given in the problem description, we can also swap 66 and 11 to obtain 123457698123457698. This number has a prime factor set {2,3,7,13,23,29,113}\{2, 3, 7, 13, 23, 29, 113\}, and so the intersection set is also {2,3,7,13}\{2, 3, 7, 13\}. This number is in the ouput because it is smaller than 693457128693457128.