No.1006 Share an Integer
Problem Statement
Shinobu picked up a positive integer $X$ in England and gave it to Alice as a present.
However, since the two of them are good friends, Alice decided to share it with her amicably.
Having many divisors feels as though it might divide their friendship as well, so
the value $f(N)$ of an integer $N$ is defined as follows.
$f(N)=N-d(N)$, where $d(N)$ is the number of positive divisors of $N$
For the two of them, find all equal partitions of the integer $X$.
More precisely, find all pairs $(A,B)$ of positive integers satisfying $X=A+B$
for which $\left| f(A)-f(B)\right| $ is minimized.
If there are multiple pairs, print them in ascending order of A, following the output format below.
Input
$X$
[Constraints]
・$2\le X\le 2\times 10^6$
・$X$ is an integer.
Output
Print all pairs of integers $(A,B)$ that give the most equal partition of $X$.
Specifically, if there are $n$ pairs, print $n$ lines, each containing $A,B$ in this order, separated by a space.
The pairs must be printed in ascending order of $A$.
Sample
Sample 1
Input
21
Output
9 12 12 9
12 has 6 positive divisors, namely 1,2,3,4,6,12, so $f(12)=12-6=6$.
9 has 3 positive divisors, namely 1,3,9, so $f(9)=9-3=6$.
Therefore $\left| f(12)-f(9)\right| =0$, and the partitions $(9,12),(12,9)$ minimize the difference in value.
There are no other pairs for which the difference in value reaches the minimum of 0.
Sample 2
Input
39
Output
17 22 19 20 20 19 22 17
$f(17)=17-2=15$, $f(19)=19-2=17$, $f(20)=20-6=14$, $f(22)=22-4=18$.
$\left| f(17)-f(22)\right| =\left| f(19)-f(20)\right| =3$, and
these are the partitions that minimize the difference in value.
The difference in value cannot be made less than 3.
Sample 3
Input
489
Output
237 252 241 248 243 246 244 245 245 244 246 243 248 241 252 237
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
eSeF
tatyam