2012-03-15 22:08:31Morris

[UVA] 10127 - Ones

Problem E - 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?

Sample input

3 
7 
9901

Output for sample input

3
6
12


意思 :
111 / 3 = 37
111111 / 7 = 15873 ...

#include <stdio.h>
int main() {
    int n;
    while(scanf("%d", &n) == 1) {
        int i, tmp = 1;
        for(i = 1; ; i++) {
            if(tmp%n == 0)    break;
            tmp = tmp*10 + 1;
            tmp %= n;
        }
        printf("%d\n", i);
    }
    return 0;
}