ZOJ 1889 Ones

Ones

Time Limit: 2 Seconds       Memory Limit: 65536 KB

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



9901


Sample Output

3
6
12

题意:给出一个数N,N不是5或者2的倍数,求一个长度最小的由1组成的十进制数,满足这个数是N的倍数,输出1的个数。。。。0<N<100000
思路:如果我们写成m=m*10+1;if(m%N==0) break;count++;这样m的值会溢出。。
解释:像3这种,11进去余数为2,按原来想法我们应该让111进去,但是因为余数为2,我们把余数扩大10倍再加1,效果和111进去一样,如果这个数被除尽
那么111就被除尽
代码:
#include <stdio.h>


int main()
{
    int N;
    while(scanf("%d",&N)!=EOF)
    {
        int count=1,m=0;
        while(1){
            m=(m*10+1)%N;
            if(m==0)
                break;
            count++;
        }
        printf("%d\n",count);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值