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;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM