1.

/**
 * ACM Training 2009
 * ACM Problem #10127 - Ones
 * Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=13&problem=1068&mosmsg=Submission+received+with+ID+7417381
 *
 * @author Felix Dietrich
 * @version 1.0, 09/21/2009
 *
 * Methode: BigInteger, Modulo
 * Status : Accepted
 * Runtime: 0.656
 */

import java.math.BigInteger;
import java.util.*;

public class Main
{
    public static void main(String... s)
    {
        Scanner sc = new Scanner(System.in);
       
        int n;
        int digits;
        BigInteger b;
        BigInteger ten = BigInteger.valueOf(10);
        BigInteger input;
       
        while(sc.hasNext())
        {
            n = sc.nextInt();
            input = BigInteger.valueOf(n);
            b = BigInteger.valueOf(11);
           
            digits = 2;
            if(n == 0)
                digits = 0;
            else if(n == 1)
                digits = 1;
            else
            {
                while(b.mod(input).compareTo(BigInteger.ZERO) != 0)
                {
                    b = b.multiply(ten).add(BigInteger.ONE);
                    digits++;
                }
            }
            System.out.println(digits);
        }
    }
}

2.
/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem 10127 - Ones
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1068
* @author Miesel Christoph
* @author Seilbeck Robert
* @author Wolfram Andre
* @version 1.0 02.06.2009
*
* Status : Accepted
* Runtime: 0.100
*/


import java.util.Scanner;

public class Main
{
public static void main(String... args)
{
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
int k = 1;
int n = sc.nextInt();
int r = n==1 ? 0 : 1;
while(r != 0)
{
r = (r*10+1) % n;
k++;
}
System.out.println(k);
}
}
}