2013
11-11

# Ones

Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple of n?

Each line contains a number n.

Output the number of digits.

3
7
9901


3
6
12


//* @author 洪晓鹏<[email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */>
import java.util.Scanner;

public class Main {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
while(in.hasNext())
{
int input = in.nextInt();
int result = 1;
int begin = 1;
while(true)
{
if(begin % input ==0)
{
System.out.println(result);
break;
}
begin = begin%input;
begin = begin*10 + 1;
result ++;
}
}
}
}