Skip to main content
LIVE CONTEST: ALGOR Contest: Round #4 (Special Challenge) is live now!

~/algor $ cat problems/sonlar-onli-kasr-davri

Period of a decimal fraction

Medium 1000 ms 128 MB 66%
Share

You are given a positive integer $n$. When the fraction $\frac{1}{n}$ is written as a decimal, after the decimal point there first come $k$ digits outside the period, and then a period of $d$ digits repeats forever. Find $k$ and $d$ ($k$ and $d$ must be the smallest possible; if the decimal terminates, $d = 0$). For example, $\frac{1}{6} = 0{,}1(6)$: $k = 1$, $d = 1$; $\frac{1}{7} = 0{,}(142857)$: $k = 0$, $d = 6$; $\frac{1}{4} = 0{,}25$: $k = 2$, $d = 0$.

The remainders of the long division of one by n; the period starts where a remainder repeats

Input

One positive integer $n$.

Output

Two integers separated by a space: $k$ and $d$.

Note

$2 \le n \le 10^{9}$

Examples

Input #1
6
Output #1
1 1
Input #2
7
Output #2
0 6

Sign in to submit a solution

Signing up is free and takes a minute.