Problem A: 深入浅出学算法002-n个1

Description

由n个1组成的整数能被K(K<10000)整除,n至少为多少?

Input

多组测试数据,第一行输入整数T,表示组数 然后是T行,每行输入1个整数代表K

Output

对于每组测试数据输出1行,值为n

Sample Input

1
11

Sample Output

2
#include <stdio.h>
#include <stdlib.h>
int main(void)
 {
    int t;
    while(scanf("%d",&t)!=EOF)
    { 
    while(t--)
    {
        int k;
        scanf("%d",&k);
        if(k==1)
        {
            printf("1\n");
            continue;
        }int c=1;
        int temp=1;
        while(temp!=0)
        { 
             temp=temp*10+1;
             temp=temp%k;
             c++; 
         }     
        printf("%d\n",c);
    }
    }
    return 0;
}

 

posted @ 2018-12-21 09:19  MichaelCecil  阅读(1581)  评论(0编辑  收藏  举报